[英]Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError:
[英]babel-loader: Module build failed: SyntaxError: Deleting local variable in strict mode
我在带有自定义 babel-plugin 的webpack
使用babel-loader
将一些第三方代码转换为一种格式,该格式可以通过 Webpack 的打包器顺利通过。 但是,当我的代码通过 babel 的解析器 (babylon) 运行以构建 AST 时,出现以下错误:
Module build failed: SyntaxError: Deleting local variable in strict mode
我在 bablyon 中找到了触发此消息的行: https : //github.com/babel/babylon/blob/master/src/parser/expression.js#L236
查看该代码,似乎我应该能够通过将this.state.strict
设置为false
来禁用 babylon 中的严格模式解析。 问题是我不知道如何从babel-loader
设置this.state.strict
。 我希望其他人对此有更多了解。
以下是我迄今为止尝试过的一些事情:
strict: false
和strictMode: false
query
strictMode: false
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { strict: false, plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
strict: false
和strict: false
strictMode: false
与插件
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { plugins: [ [__dirname + '/babel-plugins/custom-plugin', {strict: false}] ] } }
在custom-plugin.js
中的Program
state.opts.strict
设置为 false (但这不应该起作用,因为 babylon 解析代码并在传递 AST 进行遍历之前失败)
module.exports = function (params) { return { visitor: { Program: function (path, state) { state.opts.strict = false; } } }; };
在webpack.config.js
和.babelrc
使用blacklist
(在 babel v6 中已删除,因此无论如何这都不起作用)
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
我可以想到这个问题的一些hacky解决方案,但是这个标志应该可以通过babel-loader
或.babelrc
以某种形式在表面访问。
只需更改您的预设。 这可能会有所帮助。
presets: [
'es2015'
]
成为
presets: [
['es2015', {modules: false}]
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.