[英]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:我一直在编写一个链接到 React 的数据库,但过了一段时间我安装了一个库,它是 babel-core 和其他库,但在编译时总是出现以下错误:
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: 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" ] } {“预设”:[“@babel/preset-env”,“@babel/preset-react”]}
Remove your node_modules and follow these steps:删除您的 node_modules 并按照以下步骤操作:
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
node_modules/.bin/babel-node.cmd - windows only node_modules/.bin/babel-node.cmd - 仅限 windows
node_modules/@babel/node/bin/babel-node.js 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.
尝试安装 nvm 并使用较小的节点版本。 Also, you should use previous versions of babel packages
另外,你应该使用以前版本的 babel 包
@babel/preset-env
@babel/preset-env
@babel/preset-react
@babel/preset-react
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.