如何解决“未捕获的错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js):”

时间:2019-04-01 07:24:41

标签: node.js babeljs webpack-4 babel-loader

我在我的React应用程序中将babel与webpack一起使用。我已安装满足条件的“ babel-loader”:“ ^ 8.0.5”和“ @ babel / core”:“ ^ 7.4.0”

nil

节点:v10.5.0 npm:v6.1.0

使用guard let viewController = Bundle.main.loadNibNamed("NameOfTheNib", owner: nil, options: nil)?.first else { print("Can not find nib with that name") return } 运行应用程序 支持es6模块

package.json

"babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'".

.babelrc

node --experimental-modules lib/server.mjs

webpack.config.js

{
  "name": "advanced-react",
  "version": "1.0.0",
  "description": "Advanced React",
  "main": "lib/server.js",
  "author": "Sai",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon --exec babel-node lib/server.mjs",
    "webpack": "webpack -wd"
  },
  "devDependencies": {
    "babel-eslint": "^10.0.1",
    "eslint": "^5.15.3",
    "eslint-plugin-react": "^7.12.4"
  },
  "dependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.4.0",
    "@babel/plugin-proposal-class-properties": "^7.4.0",
    "@babel/polyfill": "^7.4.0",
    "@babel/preset-env": "^7.4.2",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-stage-2": "^7.0.0",
    "@babel/register": "^7.4.0",
    "@babel/runtime": "^7.4.2",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
    "ejs": "^2.6.1",
    "express": "^4.16.4",
    "react": "^16.8.5",
    "react-dom": "^16.8.5",
    "webpack": "^4.29.6",
    "webpack-cli": "^3.3.0"
  }
}

但是当我启动应用程序时遇到此错误

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "env",
    "react",
    "stage-2"
  ],
  "plugins": ["transform-es2015-modules-commonjs"]
}

2 个答案:

答案 0 :(得分:0)

这是一个修改

使用此工具babel-upgrade遇到了同样的问题。

这是repo https://github.com/babel/babel-upgrade

遵循readme

答案 1 :(得分:0)

尝试这种变体

npm rebuild node-sass