Javascript 找不到模块';巴贝尔核心&x27;。使用react.js、webpack和express server

Javascript 找不到模块';巴贝尔核心&x27;。使用react.js、webpack和express server,javascript,express,reactjs,webpack,babeljs,Javascript,Express,Reactjs,Webpack,Babeljs,每当我在终端中运行webpack时,我会得到: Hash: efea76b1048c3a97b963 Version: webpack 1.12.13 Time: 33ms + 1 hidden modules ERROR in Cannot find module 'babel-core' 这是我的webpack.config.js文件 module.exports = { entry: './app-client.js', output: { filename:

每当我在终端中运行
webpack
时,我会得到:

Hash: efea76b1048c3a97b963
Version: webpack 1.12.13
Time: 33ms
    + 1 hidden modules

ERROR in Cannot find module 'babel-core'
这是我的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

{
  "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安装时,您应该将babel loader和babel core作为开发人员依赖项安装

npm install babel-core babel-loader --save-dev

我刚刚遇到了这个错误,通过安装babel core解决了这个问题。 但有趣的是,我发现巴贝尔核心确实存在于巴贝尔加载器的peerDependencies中

为什么peerDependecies没有自动安装,在我在npm博客中找到一些搜索工作之后

peerDependencies将不再自动安装

npm install babel-register
这可以解决你的问题。此外,添加LRC B.法律改革委员会 { “预设”:[“es2015”,“反应”]
}

在@Chetan的回答中添加以下内容:

今天我在阅读Axel Rauschmayer博士的书时遇到了这个问题。每本书,
babel loader
也应该下载
babel core
。然而,当我尝试时,情况并非如此。我认为这与@theJian的回答有关

由于原始package.json已经将
babel loader
列为依赖项,因此运行以下命令解决了错误

npm install babel-core --save-dev

对于那些想要使用babel loader 8+:它需要babel 7.x,它将作为“@babel/core”包而不是“babel core”安装。 换句话说,运行:

npm install --save-dev @babel/core

工作得很有魅力!请记住将其添加到您的
packag.json
中,以避免再次遇到此问题。运行带有标志
-S
npm install
将完成此任务。我仍然收到:
错误:找不到模块“@babel/core”babel-loader@8需要Babel 7.x(包'@Babel/core')。如果你想使用Babel 6.x(“Babel-core”),你应该安装“Babel”-loader@7“
看起来loader v8需要core v7,但core v7目前只有一个
beta
版本,这似乎是维护人员的疏忽。我手动指定了
babel loader
(最新版本)的
7.1.5
,现在我正在关机运行为什么?你能解释一下为什么这会起作用吗?那么我猜你没有使用babel loader 8+。我为那些碰巧正在升级/启动一个新项目但不知道为什么因为包重命名而无法工作的人回答了这个问题。在清楚说明适用于哪个版本时,无需否决。