如何在为React设置Webpack时修复'npm run' 'npm run'?

我正在运行一个React教程,当我在我的项目上运行 npm run 时遇到了这个问题 . 较大的错误代码是:

./src/index.jsx中的错误模块构建失败(来自./node_modules/babel-loader/lib/index.js):错误:不允许插件/预设文件导出对象,仅导出函数 . 在/S8L27nodeproject/node_modules/babel-preset-react/lib/index.js中

看看类似的问题,我认为我的Babel版本不是最新版本,因为 babel-loader 与其他版本不同,但是当我运行 npm outdated 时,它们看起来很好 .

我的package.json文件是:

{
  "name": "s8l27nodeproject",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack -p",
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.4",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-1": "^6.24.1",
    "react": "^16.6.0",
    "react-dom": "^16.6.0",
    "webpack": "^4.25.1",
    "webpack-dev-server": "^3.1.10"
  },
  "devDependencies": {
    "@babel/core": "^7.1.5",
    "webpack-cli": "^3.1.2"
  }
}

虽然我的webpack.config.js文件是:

module.exports = {
    entry: [
        './src/index.jsx'
    ],
    output: {
        filename: './bundle.js'
    },
    module: {
        rules: [{
            exclude: /node_modules/,
            loader: 'babel-loader'
        }]
    }
}

有谁知道我能做些什么来解决这个问题?

回答(0)