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
andstrictMode: false
inquery
{ test: /\.js$/, include: /bower_components/, //only thirdparty loader: 'babel', query: { strict: false, plugins: [__dirname + '/babel-plugins/custom-plugin'] } }
strict: false
andstrictMode: 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 inProgram
withincustom-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
inwebpack.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.