简体   繁体   中英

Babel 6 react JSX transformer - disable strict

Issue

I'm using babel 6 for react JSX transforms. However I'm not using the react preset, I am ONLY using the 'transform-react-jsx' plugin (and trying strict-mode disable option), here is my .babelrc

{
  "plugins": [
    ["transform-react-jsx"]
  ],
  "sourceMaps": true,
  "strictMode": false
}

However I have required a thirdparty javascript that uses 'with' (out of my control) which emits following error: [SyntaxError: foo.js: 'with' in strict mode .. ]

So I need to disable strict mode, This is same problem as this issue however I am NOT using es6/es2015 stuff, only jsx transforms.

With babel 6 there is no blacklist and I've only specified ONE plugin, so I'm suspect there is no way to disable.

According to this line , the strictMode option is indeed parsed.

I don't understand the syntax you used for your .babelrc , though. Why an array?

Try this:

{
  "plugins": [
    ["transform-react-jsx"]
  ],
  "sourceMaps": true,
  "strictMode": false
}

transform-strict-mode is used only to include the strict mode not to disable it. So setting it to false ["transform-strict-mode", {"strict": false}] will change nothing, in your case better remove this plug-in then including it. But if somewhere else you are using a plugin or preset that includes the strict mode, try maybe to use es2015-loose :

  1. install

    npm install --save-dev babel-preset-es2015-loose babel-preset-es2015

  2. config

    {"presets": ["es2015-loose"]}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM