react-native: Incorrect Babel transforms when running with "npm link"

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:

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 21 (13 by maintainers)

Commits related to this issue

Most upvoted 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:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

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 to npm install, it will remove folders that are not in your package.json, erasing your current work.

Believe me, it hurts.

@Exilz I think most of us are making changes to our librares under node_modules and then copy and pasting to the proper folder…

Any update on this issue ? I used to work directly in node_modules (horrible I know, but at least I could work). But now, because of this issue https://github.com/facebook/react-native/issues/11301 i cannot even work anymore.

🆘

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.