簡體   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