Webpack/插件/预设文件不允许导出对象,仅可导出功能 [英] Webpack/ Plugin/Preset files are not allowed to export objects, only functions

查看:70
本文介绍了Webpack/插件/预设文件不允许导出对象,仅可导出功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装babel-polyfill和babel-preset-es2015之后,我出现了一个错误:插件/预设文件不允许导出对象,只能导出功能.

after installing babel-polyfill and babel-preset-es2015 I have an error: Plugin/Preset files are not allowed to export objects, only functions.

这是 package.json

 "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/plugin-proposal-class-properties": "^7.4.4",
    "@babel/preset-env": "^7.4.5",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.6",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "browser-sync": "^2.26.5",
    "browser-sync-webpack-plugin": "^2.2.2",
    "redux-devtools": "^3.5.0",
    "webpack": "^4.32.2",
    "webpack-cli": "^3.3.2",
    "webpack-notifier": "^1.7.0"
  }

.babelrc

{
  "presets": [ "@babel/preset-env", "@babel/preset-react", "es2015", "stage-0" ],
  "plugins": [ "@babel/plugin-proposal-class-properties" ]
}

推荐答案

此错误与您的项目中发现了一些旧的babel内容有关.

This error is related to some old babel stuff being found in your project.

对于您的预设,您的"@ babel/preset-env"和"@ babel/preset-react"已更新为最新,但是es2015和stage-0是较早的依赖项,还需要更新并更换.

In your case in your presets you have the "@babel/preset-env" and "@babel/preset-react" updated to the latest, but the es2015 and stage-0 are older dependencies and also need to be updated and replaced.

因此对于es2015,因为您正在运行@ babel/preset-env,我实际上并不认为您需要运行es2015或stage-0,但是只要您将它们包含在预设中,您就可以错误.

So in the case of es2015 since you are running @babel/preset-env I don't actually think you need to run es2015 or stage-0, but as long as you have them in your presets you will be getting the error.

另外,您应该考虑提供完整的错误,例如,在我的情况下,它是类似

Also you should consider providing the full error, for example in my case it was something like

ERROR in ./demo2.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 /Users/bryanrasmussen/projects/Tiling/demo/node_modules/babel-preset-es2015/lib/index.js
    at createDescriptor (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at /Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at /Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/config-descriptors.js:58:104
    at cachedFunction (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/@babel/core/lib/config/caching.js:62:27)
    at cachedFunction.next (<anonymous>)
    at evaluateSync (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/gensync/index.js:244:28)
    at sync (/Users/bryanrasmussen/projects/Tiling/demo/node_modules/gensync/index.js:84:14)

因此,您可以看到那里的额外信息如何帮助尝试查看您问题的人意识到问题出在哪里.

So you can see how that extra information there might help someone trying to look at your question realize where the problem is at.

这篇关于Webpack/插件/预设文件不允许导出对象,仅可导出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆