I'm using babel-loader
in webpack
with a custom babel-plugin to transform some thirdparty code into a format that passes through Webpack's bundler without trouble. However, when my code runs through babel's parser (babylon) to build the AST, I get the following error:
Module build failed: SyntaxError: Deleting local variable in strict mode
I found the line in bablyon that triggers this message: https://github.com/babel/babylon/blob/master/src/parser/expression.js#L236
Looking at that code, it seems like I should be able to disable strict mode parsing in babylon by setting this.state.strict
to false
. The problem is I don't know how to set this.state.strict
from babel-loader
. I'm hoping someone else knows more about this.
Here are some things I've tried so far:
strict: false
and strictMode: false
in query
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { strict: false, plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
strict: false
and strictMode: false
with plugin
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { plugins: [ [__dirname + '/babel-plugins/custom-plugin', {strict: false}] ] } }
Set state.opts.strict
to false in Program
within custom-plugin.js
(but this shouldn't work because babylon parses the code and fails before passing the AST off for traversal)
module.exports = function (params) { return { visitor: { Program: function (path, state) { state.opts.strict = false; } } }; };
Use blacklist
in webpack.config.js
and .babelrc
(which was removed in babel v6 so this shouldn't work anyway)
{ test: /\\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
I can think of some hacky solutions to this problem, but this flag should be accessible at the surface through babel-loader
or .babelrc
in some form or another.
Just change your presets. This could help.
presets: [
'es2015'
]
to be
presets: [
['es2015', {modules: false}]
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.