-
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
Incorrect Babel transforms when running with "npm link" #10882
Comments
cc @mkonicek |
I thought different Babel presets basically aren't supported, and you should be using the babel-preset-react-native everywhere. |
I'm not trying to use a non-standard Babel preset. The bug is that the standard one, babel-preset-react-native, is not applied correctly to files in the repository referenced via npm link. |
I think the babel preset should always be defined in the You should specify "react" as a peerDependency in your |
@ericvicenti Which repository's package.json are you referring to? In the repro that I've posted, the main repository (which was created with Similarly, the main repository has a standard .babelrc containing babel-preset-react-native, and the component repository has no babelrc. This was all specified in my original report. |
The "an arbitrary React component that I do not control" should absolutely have react as a peerDependency, because it is a React component (even for functional components, JSX depends on React). From my understanding, the component repository SHOULD have a babelrc that points to the rn preset. I know you aren't the component author in this case, but maybe you can submit a PR to the repo to fix these things? Or you could fork it. |
The proposed fix -- adding .babelrc, plus a devDependencies entry on babel-preset-react-native -- solves half the problem. The component now fails to load with:
(The workarounds proposed in that error message don't fix the problem.) If I give react-native-snap-carousel a dev dependency on react, rather than a peer dependency, then everything renders. That's the second half of the workaround that I described in my original report. Unfortunately, that workaround breaks for components that depend on react-native (unlike react-native-snap-carousel, but like the non-oss components that caused me to file this bug). If you add a dev dependency on react-native in the component, then you end up with errors like the following when running
And that error is where my knowledge of React internals is exceeded. It looks to me like one of the following holds:
|
@artdent same problem as yours, any progress? |
Same problem, I can't find a proper workaround that solves every case. |
@artdent every react project should have both a peerDependency and a devDependency on react. |
@ljharb That's sensible. If the project also imports, say, react-native and third-party components like react-native-mixpanel, should it include those in both peerDependencies and devDependencies? (My instinct is yes: for instance, unit tests won't work in that repository unless you have dev dependencies.) |
Yes. In every npm project, full stop, any form of dependency that's a singleton should be a peer dep with as wide a semver range as possible; anything that's a peer dep should also be a dev dep. |
Two changes: - Set the dev and peer dependencies correctly. This happens to not be necessary for react-native-easy-toast as it is written, but it would be necessary if e.g. we were writing unit tests for this component. - Add a babelrc, required for compilation when running with 'npm link'.
This triggers the bug being investigated at facebook/react-native#10882.
Thanks for the confirmation. That makes it pretty easy to isolate this bug. It occurs when the main project depends on 'react-native' and a component project, linked with Here's the output of running
The component repository that demonstrates this is https://github.com/artdent/react-native-easy-toast. It's a fork of an arbitrary react-native component with one extra commit to fix up its deps in a manner that exposes the bug. I've also pushed an extra commit to the main project, https://github.com/artdent/NpmLinkDemo, to use the new component and trigger the bug. |
For those also encountering this bug:
For the react-native maintainers:
|
Any update on this issue ? I used to work directly in 🆘 |
|
How do people even work on modules since then ?? I don't understand how this issue is still there |
@Exilz I think most of us are making changes to our librares under |
@javiercr that's what I thought... PSA : Don't ever Believe me, it hurts. |
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally! If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution. |
Description
If you use "npm link" (or "yarn link") on a React Native component repository imported by your main repository, the wrong Babel presets are used in the component repository.
Edit: the Babel error is fixable by adding the correct devDependencies in the component, but doing so exposes other problems during packaging. See below for updated repro steps.
Reproduction
https://github.com/artdent/NpmLinkDemo demonstrates the problem. This is a stock repository created from
react-native init
0.37.0, with one extra commit to import and use an arbitrary component, 'react-native-snap-carousel'.Component repository:
Main repository:
Expected behavior: the component attempts to render.
Actual behavior:
SyntaxError /Users/jacob/triggr/react-bug-repro/react-native-snap-carousel/index.js: Unexpected token (6:21)
The SyntaxError is on the 'static' keyword, which should be permitted by react-native Babel preset. Likewise with the spread operator. If you remove those unsupported features, you get syntax errors at the places that use JSX.
I had to do two workarounds in react-native-snap-carousel to get it working as it did without 'yarn link': add a .babelrc with the react-native preset, and add react as an explicit dependency. Neither of these should be necessary. (And the latter can cause version collisions very quickly.)
I believe that this is not the same issue as #637 (initial symlink support for the packager) or #4968 (nonspecific import resolution caching problems).
Additional Information
The text was updated successfully, but these errors were encountered: