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

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.



Solution 1:[1]

Try delete lock files (yarn.lock / package-lock.json) and node_modules and reinstalling again

npm install --save core-js

Solution 2:[2]

If you (or your deployment software/service) are using rsync in your deployment process and use the -C parameter then the core directory is being ignored for transfer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phuc Nguyen
Solution 2 James Taylor