Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'core-js/core/array'

Tags:

reactjs

I'm trying to find out why I get this intermittent error. Everything in the project is working as expected until this error comes up. I've rebuilt this project twice now and each time this error pops up randomly. Stopping and starting django and npm didn't clear it either. The first time I could not find it but this time, I was able to trigger the error, remove the code that I thought triggered the error but the error still remains. I am not able to see where this error is coming from or what triggered the error.

The code that triggered the error

.then(data => {
    console.log(data)
    if(isArray(data.username[0])){
        console.log(data)
    }
})

Once I removed the above code and changed it back to

.then(data => console.log(data))

I would have thought this would have removed the error, but no, the error persists.

enter image description here

I have even gone so far as the rebuild the src folder and that still didn't clear the error, then rebuild the frontend folder and that didn't clear it. I deleted and re-installed node-modules, no luck. What I ended up having to do is rebuild the entire project including the Django components.

package.json

    {
  "name": "django_react",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --watch --mode development ./leadmanager/frontend/src/index.js --output-path ./leadmanager/frontend/static/frontend/",
    "build": "webpack --mode production ./leadmanager/frontend/src/index.js --output-path ./leadmanager/frontend/static/frontend/"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.15.0",
    "@babel/plugin-transform-runtime": "^7.15.0",
    "@babel/preset-env": "^7.15.0",
    "@babel/preset-react": "^7.14.5",
    "@reduxjs/toolkit": "^1.6.1",
    "babel-loader": "^8.2.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "css-loader": "^6.2.0",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-redux": "^7.2.4",
    "react-router-dom": "^5.2.0",
    "style-loader": "^3.2.1",
    "webpack": "^5.50.0",
    "webpack-cli": "^4.8.0"
  }
}

webpack.config.json

    module.exports = {
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                }
            }
            
        ]
    }
}

.babelrc

        {
        "presets":["@babel/preset-env","@babel/preset-react"],
        "plugins": ["transform-class-properties", "@babel/transform-runtime"]
    }

This is really confusing and seems really random since it's happened twice in different places and reverting the change doesn't revert the error. I couldn't find another post that addressed this but if there is, please point me to it.

I have also tried installing core-js, but that didn't solve it either. It seems there is something stuck that I'm not seeing and not able to find. Any insight is much appreciated. Thank you in advance. I'm hoping it's something simple.

like image 909
Linus Avatar asked Oct 24 '25 17:10

Linus


1 Answers

Check that your IDE didn't automatically add an include for it. I've had this happen with VSCode adding an unnecessary include such as:

const { forEach } = require('core-js/core/array');

After finding it and removing it fixed the problem.

like image 100
Ryan Avatar answered Oct 26 '25 08:10

Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!