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

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

I`m tryng to use Babel-loader on an old project, and i notice some issues regarding when babel loader is working on wrapped objects, is this its default behaviour ? I am not sure if this is a bug or something im doing wrong, i could not find much about it over google, so this is my last resource.

Would i need to change something to my code to make it work ?

This are my current specs: Webpack: 3.19.0 babel/core: 7.0.0-beta.34 babel-loader: 8.0.0-beta.0

Please refer to my packages.json if needed:

http://paste.ubuntu.com/26187880/

I`m tryng to load a single file wrapped in a function:

http://paste.ubuntu.com/26187814/

Resuming, something old, that is built like this:

(  window.global = { } )(); 

This is my webpack config:

const webpackConfig = {     context: __dirname,     entry: {         app: '../../JavaScript/Namespacing.js'     },     module: {         rules: [           {             test: /.jsx?$/,             exclude: /(node_modules|bower_components)/,             use: {               loader: 'babel-loader',             }           }         ]     },     output: {       path: __dirname + "/../../static/js",       filename: "[name].js"     },     plugins: [         new webpack.ProvidePlugin({             $: "jquery",             jQuery: "jquery",             "window.jQuery": "jquery"         })     ], } 

And the error i get on my file is the following:

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

So, am i missing something ?

Thanks for any help.

回答1:

From your package.json, I can see that you are using older plugins and presets meant for Babel v6, which will result in this error message. You need to switch to e.g., @babel/preset-env, then update your .babelrc accordingly (if you provide .babelrc, more specific guidance can be given).

Here is a related ticket with some explanation - https://github.com/babel/babel-loader/issues/540

A few more semi-related notes on what I see in package.json:

The old babel-core dependency is still there. Remove this or update it to version 7.0.0-bridge.0. Similarly, the old react preset is in there, remove it.

If you are using the env preset, you do not need to use the es2015 preset at all. Remove it.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!