简体   繁体   English

ERROR in找不到模块'babel-core'。使用react.js,webpack和express服务器

[英]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.

相关问题 找不到模块“ babel-core”,但已安装@ babel / core - Cannot find module 'babel-core' but @babel/core is installed 模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:找不到模块'babel-core' - Module build failed (from ./node_modules/babel-loader/lib/index.js): Error: Cannot find module 'babel-core' 在React.js,node.js,webpack,babel,express中使用fs模块 - Use fs module in React.js,node.js, webpack, babel,express 如何将 babel 和 webpack 实现更新和整合到当前的最佳实践中? (错误:找不到模块“@babel/core”) - How to update and consolidate babel and webpack implementations to current best practices? (Error: Cannot find module '@babel/core') 错误:在 react.js 上找不到模块“./img.jpg” - Error: Cannot find module './img.jpg' on react.js “加载程序Users / abc / node_modules / babel-core / index.js中的错误?{” presets”:[“ react”]}未返回函数” - “ERROR in loader Users/abc/node_modules/babel-core/index.js?{”presets“:[”react“]} didn't return a function ” 使用browserify,gulp,react.js接收'错误:无法找到模块' - Receiving 'Error: Cannot find module' using browserify, gulp, react.js Webpack + Express + EJS:错误:找不到模块“.” - Webpack + Express + EJS: Error: Cannot find module “.” 错误:找不到模块 - webpack-dev-server.js - Error: Cannot find module - webpack-dev-server.js 模块无法在JSX解析,无法在webpack,babel配置中找到错误 - Module fails to parse at JSX, cannot find error in webpack, babel configs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM