最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Babel 6 react JSX transformer - disable strict - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked Mar 2, 2016 at 19:45 user2201501user2201501 10
  • If that's all you've got as your config, Babel isn't the one inserting use strict, it must be something else. Are you sure that is the only Babel config you have? You've not passing some as arguments somewhere or something? – loganfsmyth Commented Mar 2, 2016 at 20:37
  • @loganfsmyth it's the only one. I will try to reproduce on mand line without any other steps – user2201501 Commented Mar 2, 2016 at 21:02
  • if it's helpful, using a reactify transform instead works without issue. – user2201501 Commented Mar 2, 2016 at 22:26
  • 1 Well then, I'm in hell – user2201501 Commented Mar 3, 2016 at 4:02
  • 1 If that third party script uses with, it's clearly not designed to be used as a module. Leave it out of your bundler's build, and specifically request it with a <script> tag. – Jessidhia Commented Aug 9, 2016 at 9:50
 |  Show 5 more ments

2 Answers 2

Reset to default 1

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"]}

发布评论

评论列表(0)

  1. 暂无评论