-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default .babelrc #10596
Add default .babelrc #10596
Conversation
By analyzing the blame information on this pull request, we identified @hramos and @JoelMarcey to be potential reviewers. |
@@ -98,6 +98,14 @@ Node.js comes with npm, which lets you install the React Native command line int | |||
npm install -g react-native-cli | |||
``` | |||
|
|||
Ensure your version of npm is greater than 3: |
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.
What happens if they skip this step? Will it just break with npm 2?
``` | ||
npm --version | ||
``` | ||
If it is not you can update npm: |
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.
In general there are a lot of reasons that people can't update npm, so I'm concerned about adding npm 3+ as a requirement for React Native. Could this be backward-compatible instead of a breaking change somehow?
What is the rejected PR you refer to? |
@lacker Hi, the rejected PR was #7822 I'm going to try to add a specific error message if Babel is misconfigured, but trying to wrap my head around how to do that currently. I guess that would solve the specific problem in the issue referenced above. Also, then we don't have to specify a version of NPM. Can close this unless you have suggestions. |
Oh, I see what's happening now. I don't think this PR is the right way to handle it - you shouldn't make a project rely on Overall I think we really need to fix the way that React Native does transpilation nonstandardly with respect to libraries. @mkonicek and @ericvicenti might have some thoughts here too. |
It would be really nice to stop running babel on node_modules by default and have libraries publish compiled version like for the web. Another alternative would be to have the packager read some field in package.json to decide if it should compile that library or not so the migration path would be easier for lib authors. One major benefit of this is it would allow to have better babel transforms, for example we can't enable strict mode modules because externals libraries may not be compatible with it. |
I wrote up a gist on transpiled/untranspiled code here: https://gist.github.com/ide/e7b9181984933ebb0755c7367a32e7e8. It's really valuable to publish the original source code or lightly transpiled source code. Transpilation on the fly worked really well for fb www, and I think a system that supports the same will win out because it can provide a better debugging experience, can make use of modern JSVMs, can do optimizations like dead-export elimination (aka tree shaking) and so on. I think it's fine to publish transpiled code to npm, but in an additive way I find it important to also publish untranspiled (or partially transpiled) code and make use of it as we do today with the RN packager. Sorry to derail, I think we should do what we need to make Babel/RNP work better so we can keep consumer-side transpilation. |
@ide though it doesn't affect your proposal, I think you forgot one con of shipping untranspiled code (in the current situation of ).
|
OK - so I am going to close this pull request because it does not seem like the right approach. It does seem like there are some fundamental problems with the current React Native + babel approach. If someone is interested in leading an effort to fix that, I'd love to chat with them and I think I could get some folks to help out. |
This PR addresses issue #7821, where the app crashes due to a parent-directory
.babelrc
file.Previously, a PR tried to submit a fix by adding a default
.babelrc
file in new React Native projects, but was rejected so as not to add a peer dependency to react native.In this PR, a default .babelrc is created with standard presets
{ "presets": ["react-native"] }
. The docs are modified to recommend using a version of NPM greater than 3. This would ensure that the default.babelrc
does not cause any complications, as was noted by @janicduplessis for npm2.As for tests, the
.babelrc
is tested for in thelocal-cli/__tests__/generator-tests.js
file. I also ran all the internal tests withnpm test
and there was no difference in output after the specified changes.