How webpack shuts down strict mode

the with statement is used in the development process, and the webpack cannot be compiled

the reason is that strict mode cannot use with , but how to close strict mode ?

webpack :4.8.3  babel :6.26.3

in addition, the babel-plugin-transform-remove-strict-mode plug-in found on the Internet was also used, but the compilation failed.

.babelrc file

{
  "presets": [
    "es2015"
  ],
  "plugins": [
    "transform-remove-strict-mode",
    [
      "import",
      {
        "libraryName": "ramda",
        "libraryDirectory": "src",
        "camel2DashComponentName": false
      }
    ]
  ]
}
Mar.12,2021

Let's start with my conclusion, which can't be turned off when using ESM modular syntax. Of course, the conclusion may be one-sided.
originally encountered the problem that callee strict mode does not exist. After I used loader , plugin and so on, I couldn't get the specific time to add use strict string. Then I gave up and transform-remove-strict-mode also tried to be invalid.

but there is a way not to add use strict strings, that is, do not use ESM (import export) in this js file where you need to use "strict mode disable syntax", but use commonjs module syntax, that is, require and module/export . One of the ESM specifications says that using the ESM specification syntax automatically enters strict mode, so it's not sure whether this use strict is added by node, not the effect of webpack/babel.


it is recommended not to use with


it seems that you can use with
, such as

, through new Function.
const compileStatements = (statements, object) => {
  if (!statements) { return }
  statements = statements.split(';');
  statements.forEach(v => {
    if (!v) { return; }
    let parameter = v.split('=')[0]
    let fn = new Function('object', 'with(object){ return ' + v.split('=')[1] + '}')
    let value = fn(object);
    object[parameter] = value;
  })
}
Menu