I\'m using function form of \"use strict\" and don\'t want global form which Babel adds after transpilation. The problem is I\'m using some libraries that aren\'t using \"us
plugins: [
[
require("@babel/plugin-transform-modules-commonjs"),
{
strictMode: false
}
],
]
Babel 6 + es2015
We can disabled babel-plugin-transform-es2015-modules-commonjs
to require babel-plugin-transform-strict-mode
.
So comment the following code in node_modules/babel-plugin-transform-es2015-modules-commonjs/lib/index.js
at 151 line
//inherits: require("babel-plugin-transform-strict-mode"),
For babel 6 instead of monkey patching the preset and/or forking it and publishing it, you can also just wrap the original plugin and set the strict
option to false
.
Something along those lines should do the trick:
const es2015preset = require('babel-preset-es2015');
const commonjsPlugin = require('babel-plugin-transform-es2015-modules-commonjs');
es2015preset.plugins.forEach(function(plugin) {
if (plugin.length && plugin[0] === commonjsPlugin) {
plugin[1].strict = false;
}
});
module.exports = es2015preset;
just change .babelrc
solution
if you don't want to change any npm modules, you can use .babelrc
ignore like this
{
"presets": ["es2015"],
"ignore": [
"./src/js/directive/datePicker.js"
]
}
ignore that file, it works for me!
the ignored file that can't use 'use strict'
is old code, and do not need to use babel to transform it!
There's now a babel plugin that you can add to your config that will remove strict mode: babel-plugin-transform-remove-strict-mode
. It's a little ugly in that the "use strict"
gets added and then removed, but it makes the config much nicer.
Docs are in the GitHub repo: https://github.com/genify/babel-plugin-transform-remove-strict-mode
Your .babelrc ends up looking like this:
{
"presets": ["env"],
"plugins": ["transform-remove-strict-mode"]
}
Using plugins or disabling modules and strict mode as suggested in the @rcode's answer didn't work for me.
But, changing the target from es2015
|es6
to es5
in tsconfig.json
file as suggested by @andrefarzart in this GitHub answer fixed the issue.
// tsconfig.json file
{
// ...
"compilerOptions": {
// ...
"target": "es5", // instead of "es2015"
}