预设文件不允许导出对象

新手上路,请多包涵

我有一个轮播文件,我想在其中获取 index.js 并构建 block.build.js ,所以我的 webpack.config.js 是:

 var config = {
  entry: './index.js',
  output: {
    path: __dirname,
    filename: 'block.build.js',
  },
  devServer: {
    contentBase: './Carousel'
  },
  module : {
    rules : [
      {
        test: /.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['react', 'es2015'],
          plugins: ['transform-class-properties']
        }
      }
    ]
  }
};
module.exports = config;

我使用的 package.json 如下:

 {
  "name": "carousel",
  "version": "1.0.0",
  "description": "",
  "main": "webpack.config.js",
  "dependencies": {
    "@babel/core": "^7.0.0-beta.40",
    "babel-cli": "^6.26.0",
    "babel-loader": "^8.0.0-beta.0",
    "babel-plugin-lodash": "^3.3.2",
    "babel-plugin-react-transform": "^3.0.0",
    "babel-preset-react": "^6.24.1",
    "cross-env": "^5.1.3",
    "lodash": "^4.17.5",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-swipeable": "^4.2.0",
    "styled-components": "^3.2.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "webpack --watch",
    "start": "webpack-dev-server --open",
    "build": "webpack"
  },
  "devDependencies": {
    "webpack": "^4.1.1",
    "webpack-cli": "^2.0.10",
    "webpack-dev-server": "^3.1.0"
  },
  "author": "brad traversy",
  "license": "ISC"
}

…但我收到此错误消息:

 ERROR in ./index.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions.

有谁知道如何解决这个问题?

原文由 sonia maklouf 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 649
2 个回答

您正在使用 Babel 6 和 Babel 7 的组合。不能保证跨版本的兼容性:

 "@babel/core": "^7.0.0-beta.40",
"babel-cli": "^6.26.0",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"babel-preset-react": "^6.24.1",

应该

"@babel/core": "^7.0.0-beta.40",
"@babel/cli": "^7.0.0-beta.40",
"babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-react-transform": "^3.0.0",
"@babel/preset-react": "^7.0.0-beta.40",

    query: {
      presets: ['react', 'es2015'],
      plugins: ['transform-class-properties']
    }

将会

    query: {
      presets: ['@babel/react', '@babel/es2015'],
      plugins: ['@babel/proposal-class-properties']
    }

我也很困惑,因为您没有在 @babel/proposal-class-properties package.json ,但假设它在那里也应该更新。

原文由 loganfsmyth 发布,翻译遵循 CC BY-SA 3.0 许可协议

它发生在我身上,对我来说一个简单的解决方案是卸载 babel-loader@8^@babel/core

 npm uninstall --save babel-loader
npm uninstall --save @babel/core

…然后安装版本 7 babel-loader:

 npm install --save-dev babel-loader@^7

原文由 Kevin Youn 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题