[英]ERROR in Cannot find module 'babel-core'. using react.js, webpack, and express server
Whenever I run webpack
in the terminal I get: 每当我在终端中运行
webpack
时,我得到:
Hash: efea76b1048c3a97b963
Version: webpack 1.12.13
Time: 33ms
+ 1 hidden modules
ERROR in Cannot find module 'babel-core'
Here is my webpack.config.js file 这是我的webpack.config.js文件
module.exports = {
entry: './app-client.js',
output: {
filename: 'public/bundle.js'
},
module: {
loaders: [
{
exclude: /(node_modules|app-server.js)/,
loader: 'babel'
}
]
}
}
package.json 的package.json
{
"name": "react",
"version": "1.0.0",
"description": "React polling app",
"main": "app-client.js",
"dependencies": {
"babel-loader": "^6.2.2",
"bootstrap": "^3.3.6",
"express": "^4.13.4",
"react": "^0.14.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
你应该在npm install时安装babel-loader和babel-core作为dev-dependency。
npm install babel-core babel-loader --save-dev
For those wanting to use babel-loader 8+: it requires Babel 7.x,, which is to be installed as the '@babel/core' package instead of 'babel-core'. 对于那些想要使用babel-loader 8+的人:它需要Babel 7.x ,,它将被安装为'@ babel / core'包而不是'babel-core'。 In other words, run:
换句话说,运行:
npm install --save-dev @babel/core
I just meet this error, and solved by installing babel-core. 我刚刚遇到这个错误,并通过安装babel-core解决了。 But the interesting is I found babel-core does exist in babel-loader's peerDependencies.
但有趣的是我发现babel-core确实存在于babel-loader的peerDependencies中。
https://github.com/babel/babel-loader/blob/master/package.json https://github.com/babel/babel-loader/blob/master/package.json
Why peerDependecies not install automatically, after a few searching work I found this in npm blog. 为什么peerDependecies没有自动安装,经过几次搜索工作后我在npm blog中找到了这个 。
peerDependencies will not automatically install anymore. peerDependencies不再自动安装。
Adding to @Chetan's answer on this thread: 在这个帖子中添加@ Chetan的答案:
I ran into this issue today while following through Dr. Axel Rauschmayer's book here . 我同时通过阿克塞尔Rauschmayer先生博士的书下面今天就遇到了这个问题在这里 。 Per book,
babel-loader
should download babel-core
as well. 每本书,
babel-loader
应该下载babel-core
。 However this is not the case when I tried it out. 然而,当我尝试它时,情况并非如此。 I think this relates to @theJian's answer.
我认为这与@ theJian的答案有关。
Since the original package.json already lists babel-loader
as dependency, running the following command resolved the error. 由于原始package.json已将
babel-loader
列为依赖项,因此运行以下命令可解决该错误。
npm install babel-core --save-dev
npm install babel-register
This can solve your issue. 这可以解决您的问题。 Additionally, add babelrc .babelrc { "presets" : ["es2015", "react"] }
另外,添加babelrc .babelrc {“presets”:[“es2015”,“react”]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.