简体   繁体   中英

Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-core'

I have been programming a database that is linked to React, but after a while I installed a library that is babel-core and other libraries, but always when compiling I get an error that is the following:

ERROR in ./src/app/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'babel-core'


    {
      "name": "Mern-Stack-Example",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "start": "nodemon node src/app.js",
        "webpack": "webpack --mode development"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "devDependencies": {
//These
        "@babel/cli": "^7.12.10",
        "@babel/core": "^7.12.10",
        "@babel/node": "^7.12.10",
        "@babel/preset-env": "^7.12.11",
        "@babel/preset-react": "^7.12.10",
        "babel-loader": "^7.1.5",
        "nodemon": "^2.0.7",
        "webpack": "^5.17.0",
        "webpack-cli": "^4.4.0"
      },
      "dependencies": {
        "cors": "^2.8.5",
        "express": "^4.17.1",
        "mongoose": "^5.11.13",
        "morgan": "^1.10.0",
        "react": "^17.0.1",
        "react-dom": "^17.0.1"
      }
    }

But I have changed it and the error keeps appearing, I don't know how to solve it, if someone knows please help me

Webpack.Confg:

module.exports = {
    entry: './src/app/index.js',
    output: {
      path: __dirname + '/src/public/js',
      filename: 'bundle.js'
    },
    module: {
      rules: [
        {
          use: 'babel-loader',
          test: /\.js$/,
          exclude: /node_modules/
        }
      ]
    }
  };

And.Babel

{ "presets": [ "@babel/preset-env", "@babel/preset-react" ] }

Remove your node_modules and follow these steps:

 npm install --save-dev @babel/core @babel/cli @babel/preset-env @babel/node

Then, check the existence of these files:

node_modules/.bin/babel-node

node_modules/.bin/babel-node.cmd - windows only

node_modules/@babel/node/bin/babel-node.js

Generally, these issues might come in due to the version conflicts. Try to install nvm and use lesser node version. Also, you should use previous versions of babel packages

@babel/preset-env

@babel/preset-react

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM