Incorrect Babel transforms when running with "npm link"
See original GitHub issueDescription
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:
git clone https://github.com/archriss/react-native-snap-carousel
cd react-native-snap-carousel
yarn link
Main repository:
git clone https://github.com/artdent/NpmLinkDemo
cd NpmLinkDemo
yarn install
yarn link react-native-snap-carousel
npm start
react-native run-ios
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
- React Native version: 0.37.0
- Other versions: yarn 0.16.1, npm 3.9.5, node 6.2.2, react-native-cli 1.2.0, react 15.3.1
- Platform: both
- Operating System: MacOS
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (13 by maintainers)
Top GitHub Comments
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.
@javiercr that’s what I thought…
PSA : Don’t ever
yarn
while doing this, because contrary tonpm install
, it will remove folders that are not in yourpackage.json
, erasing your current work.Believe me, it hurts.