-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
npm module should be precompiled to ES5 #7850
Comments
I created a product pains entry for this: https://productpains.com/post/react-native/solve-a-ton-of-issues-by-precompiling-the-npm-module-to-es5 |
Progress so far on master:
For testing purposes I just moved the src folder (the original source) elsewhere and ran the packager again. Now I don't get warnings by the packager but an Execution exception on the phone. The error in
|
In your custom package can't you extend babel-preset-react-native? For various reasons I don't think we'd want to ship a transpiled version, it also wouldn't match what we use internally, which could lead to incompatibilities. |
I don't know. React-native is the first npm-project I know of, that relies on it's dependencies to compile it's source. I made a styling library (https://github.com/fab1an/react-native-tachyons) which needs to call the I think this coupling makes depending code extremely brittle. Just having an unrelated I frankly don't see the point of not publishing it precompiled. The packager can still compile the developer's code? My guess is it's because of node-haste which facebook uses internally? If it's not going to be precompiled than another idea would be to
|
@javache Can you outline the problems in transpiling? In my experience, not shipping a transpiled version causes lots of compatibility issues,
@fab1an I don't think haste modules will cause issues here. Since we only want to transpile code, not bundle it. |
These are the issues with transpiling I can think of. If they are addressed I would be in support of transpiling:
|
I'm in favor of fixing this. We could look into making it so that we search for |
@ide Thanks your comments. syntax: I think many codebases nowadays too are ES6 + static props (+ async/wait). Mine are. I just sometimes use additional babel-plugins for code-generation and the like. npm publishing: I want to point out
I think the packager should compile everything inside react-native (not everything smooth development: So a main-requirement is for you to be able to work "inside" node_modules fast. Shouldn't that be possible with plain |
@ide great points 👍
Certainly a difficult problem to solve. I wonder how this works for other FB projects which are written in ES6 and published as transpiled code, e.g. - https://github.com/facebook/draft-js
I'm not sure if packager reads
As per my understanding,
Since I've a crazy idea, which I think should solve most of the problems, except the source-map one. How about, we don't publish the transpiled version, but publish the source as always. When the packager starts up, and code in react-native has changed, it'll transpile it before anything else, as a separate step which uses
We already had some discussion regarding pre-compiling, which can be useful - https://www.facebook.com/groups/reactnativeoss/permalink/1528961550733807/ |
Related - #8074 |
@satya164 that sounds like a solution, but too rnative developers start the packager everytime anew? Or how would it detect changes? Maybe it can be solved with just separate babel-passes. |
@fab1an packager can maintain a cache for this I guess. |
+1 for transpiling to ES5 - the current react native behavior goes against npm best practices. Jest requires special hacks to support this, and a lot of tools simply don't work with react native because they assume shipping es5. |
I have an internal task for this. |
I just spent two hours debugging another case where packaging didn't work :( : react-native picked up a Addendum: |
Should I open a separate issue for the |
Really glad the source of this issue seems to have been identified. The linked to |
Any activity on this? This just cropped up for me again and is a PITA to get back to a working state. |
To give an update, there have been a bunch of discussions and I think people agree that 1/ the ideal state would be shipping ES5 and 2/ it's a nontrivial amount of work to get there. The last person who vaguely promised to think about this more and hinted that he might be the right person to deal with this without concretely committing to anything was @cpojer so I'll tag him in this sentence. |
Let's continue this in #10966. |
The JS-code that react-native exports in
package.json
main should be es5, precompiled by babel.There a lot of issues popping up right now, because all code and libraries that depends on react-native need to know how to compile react-native as well, which is difficult to get right, and changes over time.
One such bug: vitalets/react-native-extended-stylesheet#10
It also breaks code with custom
.babelrc
.I have already started trying to precompile it and documented in this issue, which I will close: #7666
Here is the branch with my preliminary work: https://github.com/fab1an/react-native/tree/precompile-babel.
The text was updated successfully, but these errors were encountered: