我正在使用 Babel(7.5.0 版)和 NodeJS 最新版(12.x)。因此,扩展运算符已经被 NodeJS 处理了,我不希望 babel 对其进行处理。
这是我的 .babelrc 文件:
{
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
],
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"node": "current"
},
"useBuiltIns": "usage"
}
]
]
}
这是我的错误:
ERROR in ./src/utils/logger/logger.js
Module build failed: ReferenceError: Unknown helper objectSpread2
at loadHelper (/app/node_modules/@babel/helpers/lib/index.js:238:27)
at Object.getDependencies (/app/node_modules/@babel/helpers/lib/index.js:279:21)
at File.addHelper (/app/node_modules/@babel/core/lib/transformation/file/file.js:204:33)
at PluginPass.addHelper (/app/node_modules/@babel/core/lib/transformation/plugin-pass.js:31:22)
at PluginPass.ObjectExpression (/app/node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js:379:25)
at newFn (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitSingle (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:90:19)
at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:146:19)
at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitMultiple (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:85:17)
at TraversalContext.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:144:19)
at Function.traverse.node (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/index.js:94:17)
at NodePath.visit (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/path/context.js:95:18)
at TraversalContext.visitQueue (/app/node_modules/@babel/core/node_modules/@babel/traverse/lib/context.js:118:16)
@ ./src/app.js 5:0-40
@ multi ./src/app.js
我读到需要安装一些插件,但我认为那是针对较旧的nodejs版本,我不明白为什么要为内置在nodejs中的功能安装插件。
如何做到这一点?
更新:
我在这里创建了一个问题:https://github.com/babel/babel-loader/issues/798。
v10.16.0
中成功使用spread
运算符。 - Usama Tahirv12.x
一起使用,但在v10.16.0
上可以正常工作? - Bilal