Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable strict mode for transform-es2015-modules-commonjs
Summary:Since #5422 react-native works with strict mode modules but the transform was not updated since Facebook has some non strict mode compatible internal modules. Now that #5214 has landed and it is easy to change the babel config I think we should enable it by default to make es2015 modules spec compliant. Someone at Facebook will have to make the internal changes necessary to disable strict mode modules for their projects that use non strict mode compatible modules by including a .babelrc file with ``` json { "presets": [ "react-native" ], "plugins": [ ["transform-es2015-modules-commonjs", { "strict": false, "allowTopLevelThis": true }] ] } ``` before merging this. We might also want to mention this in the breaking change section for the next release. Closes #5796 Differential Revision: D3075802 fb-gh-sync-id: e807b67401107e1e944db38453e254025ce0a6c7 shipit-source-id: e807b67401107e1e944db38453e254025ce0a6c7
- Loading branch information
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the .babelrc override mentioned in the commit message doesn't seem to work - when I use it, strict mode is still enabled.
looks like the ability to override presets in Babel 6 is a work in progress.
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you cleared the packager cache to make sure all the transforms are run again? (node ./node_modules/react-native/local-cli/cli.js start --reset-cache)
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it still happens.. I put together a minimal case.. just apply this patch over an empty 'react-native init' (RN 0.22) project. the error evaluating 'n.navigator', due to Firebase not being strict-mode compatible, happens even with a .babelrc that overrides the preset.
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keeth I think you can put firebase in Babel's ignore list.
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satya164 yay, this fixed the issue of babel turning on strict mode for firebase.js, thank you!
echo node_modules/firebase/lib/firebase-web.js > .babelignore
I think the preset override issue still stands (that the {strict: false} override mentioned above appears to have no effect).
But putting firebase in .babelignore solves my original problem (I no longer need to keep babel-preset-react-native pinned at 1.5.2), so thanks!
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put together a repro case and open a issue for that? I'll try to find out why it doesn't work anymore.
36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janicduplessis Applying the diff @keeth shared on a project generated by
react-native init
should do.36893ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #6611
Thanks a lot for the ignore hint, it sounds like others are having this problem with Firebase (#6566).