找不到模块'@ babel / core'

在他运行npm的那一部分开始之前,我一直严格按照它进行操作。不同之处在于,他的应用程序运行了,而我的却得到了错误:

找不到模块’@ babel / core’

完整错误:

ERROR in ./src/index.js

Module build failed (from ./node_modules/babel-loader/lib/index.js):

Error: Cannot find module '@babel/core'

at Function.Module._resolveFilename (module.js:547:15)

at Function.Module._load (module.js:474:25)

at Module.require (module.js:596:17)

at require (internal/module.js:11:18)

at Object.<anonymous> (C:\Users\joeyf\Desktop\Code\Github\webpack4-sample\node_modules\babel-loader\lib\index.js:5:15)

at Module._compile (module.js:652:30)

at Object.Module._extensions..js (module.js:663:10)

at Module.load (module.js:565:32)

at tryModuleLoad (module.js:505:12)

at Function.Module._load (module.js:497:3)

@ multi (webpack)-dev-server/client?http://localhost:8080 (webpack)/hot/dev-server.js ./src/index.js main[2]

我试图重新安装babel-core,但仍然找不到。这是我的package.json:

{

"name": "webpack4-sample",

"version": "1.0.0",

"description": "A sample setup of Webpack4 with React and Babel",

"main": "index.js",

"scripts": {

"start": "webpack-dev-server --mode development --open --hot",

"build": "webpack --mode production"

},

"author": "Joey Fenny",

"license": "ISC",

"dependencies": {

"babel": "^6.23.0",

"babel-cli": "^6.26.0",

"react": "^16.4.2",

"react-dom": "^16.4.2"

},

"devDependencies": {

"babel-core": "^7.0.0-rc.4",

"babel-loader": "^8.0.0",

"babel-preset-env": "^1.7.0",

"babel-preset-react": "^6.24.1",

"html-webpack-plugin": "^3.2.0",

"webpack": "^4.17.1",

"webpack-cli": "^3.1.0",

"webpack-dev-server": "^3.1.6"

}

}

我的webpack.config.js:

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {

entry: './src/index.js',

output: {

path: path.join(__dirname, '/dist'),

filename: 'index_bundle.js'

},

module: {

rules: [{

test: /\.js$/,

exclude: path.join(__dirname, '/node_modules'),

use: {

loader: 'babel-loader'

}

}]

},

plugins: [

new HtmlWebpackPlugin({

template: './src/index.html'

})

]

}

这是git repo的链接:

https://gitlab.com/jfny/webpack4-sample

有人知道发生了什么吗?谢谢。

回答:

尝试运行此。

npm install @babel/core --save

babel改变了他们的包裹,所以您的包裹babel-core将与您的包裹相同@babel/core

以上是 找不到模块&#39;@ babel / core&#39; 的全部内容, 来源链接: utcz.com/qa/420800.html

回到顶部