繁体   English   中英

babel-loader:模块构建失败: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 我希望其他人对此有更多了解。

以下是我迄今为止尝试过的一些事情:

  1. strict: falsestrictMode: false query strictMode: false

     { test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { strict: false, plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
  2. strict: falsestrict: false strictMode: false与插件

    { test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { plugins: [ [__dirname + '/babel-plugins/custom-plugin', {strict: false}] ] } }
  3. custom-plugin.js中的Program state.opts.strict设置为 false (但这不应该起作用,因为 babylon 解析代码并在传递 AST 进行遍历之前失败)

     module.exports = function (params) { return { visitor: { Program: function (path, state) { state.opts.strict = false; } } }; };
  4. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM