如何修复错误“不允许插件/预设文件导出对象”?

时间:2019-05-06 16:43:04

标签: reactjs webpack

我继承了一个几年没有碰到的项目。因此,我的第一步是升级所有依赖项。我已经接近使其工作了,但我陷入了这一错误:

Error: Plugin/Preset files are not allowed to export objects, only functions

我尝试从webpack.config.js文件中删除规则。那没什么帮助。该项目最初引用了“ es2015”,我将该信息更新为使用“ es2016”。

这是我的package.json文件

{
  "name": "quant-engine",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "private": true,
  "scripts": {
    "start": "webpack-dev-server --progress --inline --port 8112",
    "build": "webpack",
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "acorn": "^6.1.1",
    "babel-core": "^6.17.0",
    "babel-loader": "^8.0.5",
    "babel-preset-es2016": "^6.24.1",
    "babel-preset-react": "^6.5.0",
    "chai": "^4.2.0",
    "css-loader": "^2.1.1",
    "file-loader": "^3.0.1",
    "font-awesome": "^4.7.0",
    "moment": "^2.18.1",
    "prettier": "^1.17.0",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-bootstrap": "^1.0.0-beta.8",
    "react-currency-input": "^1.2.6",
    "react-date-picker": "^7.5.1",
    "react-dom": "^16.8.6",
    "react-fontawesome": "^1.6.1",
    "style-loader": "^0.23.1",
    "webpack": "^4.30.0",
    "webpack-dev-server": "^3.3.1"
  },
  "devDependencies": {
    "@storybook/addon-actions": "^5.0.11",
    "@storybook/addon-links": "^5.0.11",
    "@storybook/addons": "^5.0.11",
    "@storybook/react": "^5.0.11",
    "webpack-cli": "^3.3.2"
  }
}

这是我的webpack.config.js文件

module.exports = {
  entry: './src/app.js',
  },
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
  module: {   
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: { presets: [ 'es2016', 'react' ] }
      },
      {
        test: /\.(png|jpg|gif)$/,
        loader: 'file-loader',
        exclude: /node_modules/,
        options: {}
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader'
      }
    ]
  }
};

我不熟悉babel。据我所能find,其他人posted这个problem没有任何结果(但是他们的问题从未得到充分解释)。

我希望所有项目依赖项都尽可能最新。我不想尽可能downgrade

Thnx

编辑:在下面构建输出。我没有.babelrc文件。

# npm start

> quant-engine@1.0.0 start C:\src\projects\OptionAnalyzer\web
> webpack-dev-server --progress --inline --port 8112

 10% building 1/1 modules 0 activei 「wds」: Project is running at http://localhost:8112/
i 「wds」: webpack output is served from /
× 「wdm」: Hash: c72e7c421021f65f90e2
Version: webpack 4.30.0
Time: 1030ms
Built at: 2019-05-07 14:40:23
    Asset     Size  Chunks             Chunk Names
bundle.js  349 KiB    main  [emitted]  main
Entrypoint main = bundle.js
[0] multi (webpack)-dev-server/client?http://localhost:8112 ./src/app.js 40 bytes {main} [built]
[./node_modules/ansi-html/index.js] 4.16 KiB {main} [built]
[./node_modules/ansi-regex/index.js] 135 bytes {main} [built]
[./node_modules/html-entities/index.js] 231 bytes {main} [built]
[./node_modules/loglevel/lib/loglevel.js] 7.68 KiB {main} [built]
[./node_modules/node-libs-browser/node_modules/events/events.js] 13.3 KiB {main} [built]
[./node_modules/querystring-es3/index.js] 127 bytes {main} [built]
[./node_modules/strip-ansi/index.js] 161 bytes {main} [built]
[./node_modules/url/url.js] 22.8 KiB {main} [built]
[./node_modules/webpack-dev-server/client/index.js?http://localhost:8112] (webpack)-dev-server/client?http://localhost:8112 8.26 KiB {main} [built]
[./node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.59 KiB {main} [built]
[./node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.05 KiB {main} [built]
[./node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
[./node_modules/webpack/hot/emitter.js] (webpack)/hot/emitter.js 75 bytes {main} [built]
[./src/app.js] 1.44 KiB {main} [built] [failed] [1 error]
    + 11 hidden modules

ERROR in ./src/app.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In C:\src\projects\OptionAnalyzer\web\node_modules\babel-preset-es2016\lib\index.js
    at createDescriptor (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:178:11)
    at items.map (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:109:29)
    at createPresetDescriptors (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:101:10)
    at passPerPreset (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:58:96)
    at cachedFunction (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\caching.js:33:19)
    at presets.presets (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-descriptors.js:29:84)
    at mergeChainOpts (C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-chain.js:320:26)
    at C:\src\projects\OptionAnalyzer\web\node_modules\@babel\core\lib\config\config-chain.js:283:7
i 「wdm」: Failed to compile.

0 个答案:

没有答案