[英]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.