Babel Plugin / Preset文件不允许导出对象,仅导出函数 [英] Babel Plugin/Preset files are not allowed to export objects, only functions
问题描述
我试图在一个旧项目上使用Babel-loader,我注意到有关babel加载器何时处理包装对象的一些问题,这是它的默认行为吗?我不确定这是一个错误还是我做错了什么,我在谷歌上找不到它,所以这是我最后的资源。
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 ?
这是我目前的规格:
Webpack:3.19.0
babel / core:7.0 .0-beta.34
babel-loader:8.0.0-beta.0
This are my current specs: Webpack: 3.19.0 babel/core: 7.0.0-beta.34 babel-loader: 8.0.0-beta.0
如果需要,请参阅我的packages.json:
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 = { } )();
这是我的webpack配置:
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:
插件/预设文件不允许导出对象,只有乐趣ctions。
那么,我错过了什么吗?
So, am i missing something ?
感谢您的帮助。
推荐答案
我得到了同样的错误使用 babel 7.x
和babel-loader:^ 8.0.4
I got the same error with babel 7.x
and and "babel-loader": "^8.0.4"
我通过更改 package.json中的以下依赖项解决了这个问题。
我从这些链接中获得了解决方案
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2"
}
和 .babelrc
{
"presets": ["@babel/env", "@babel/react"]
}
或 package.json
"babel": {
"presets": [
"@babel/env",
"@babel/react"
]
},
如果您使用的是 npm
,请使用以下
If you are using npm
then use the following
npm install @babel/core --save-dev
npm install @babel/preset-env --save-dev
npm install @babel/preset-react --save-dev
npm install babel-loader --save-dev
npm install webpack --save-dev
npm install webpack-cli --save-dev
如果您使用纱线,请使用以下
If you are using yarn, then use the following
yarn add @babel/core --dev
yarn add @babel/preset-env --dev
yarn add @babel/preset-react --dev
yarn add babel-loader --dev
yarn add webpack --dev
yarn add webpack-cli --dev
这篇关于Babel Plugin / Preset文件不允许导出对象,仅导出函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!