yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.39k stars 2.73k forks source link

Issues migrating from NPM to Yarn in a React-Native projects #3936

Open PolGuixe opened 7 years ago

PolGuixe commented 7 years ago

I am able to run:

yarn

Then yarn transforms node_modules and generates de yarn.lock file. The only warnings reported are:

warning "react-komposer@1.13.1" has incorrect peer dependency "react@^0.14.3 || ^15.0.0".
warning "react-native-elements@0.12.2" has incorrect peer dependency "react-native-vector-icons@~4.1.1".

When I try to use react-native run-ios in order to compile the project I get this error:

Pols-MacBook-Pro:ReactNativeApp polguixe$ react-native run-ios
/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: /Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/react-native/local-cli/core/index.js: Unexpected token (29:2)
  27 | 
  28 | export type RNConfig = {
> 29 |   ...ConfigT,
     |   ^
  30 |   /**
  31 |    * Returns an array of project commands used by the CLI to load
  32 |    */
    at Parser.pp$5.raise (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp.unexpected (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:1716:8)
    at Parser.pp$3.parseIdentifier (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:4251:10)
    at Parser.pp$8.flowParseObjectPropertyKey (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5169:90)
    at Parser.pp$8.flowParseObjectType (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5283:26)
    at Parser.pp$8.flowParsePrimaryType (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5462:19)
    at Parser.pp$8.flowParsePostfixType (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5580:19)
    at Parser.pp$8.flowParsePrefixType (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5597:17)
    at Parser.pp$8.flowParseAnonFunctionWithoutParens (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5602:20)
    at Parser.pp$8.flowParseIntersectionType (/Users/polguixe/Developer/projects/FoodPoints/ReactNativeApp/node_modules/babylon/lib/index.js:5617:19)

It is working fine if I am using NPM.

Versions:

arcanis commented 7 years ago

It seems your babel installation doesn't find the object rest spread transform.

PolGuixe commented 7 years ago

@arcanis do I need to include a specific Babel package for that?

zbtang commented 7 years ago

I have the same problem

deavial commented 7 years ago

I had the same issue and not sure why this works (I don't see a difference in the modified files) but here is what I did:

  1. I started with a clean branch from my last working set.
  2. I uninstalled yarn (brew uninstall --force yarn)
  3. I deleted the node_modules
  4. I ran npm i
  5. I ran react-native-git-upgrade
  6. Had no merge conflicts
  7. Ran react-native run-ios and all was good
  8. reinstalled yarn

My env MacOS (up to date) Node 6.11.1 NPM 3.10.10 Don't know what yarn was before I removed it.

UPDATE This appears to be an issue with yarn. After completing the steps above I ran yarn i and bam the error came back. So I deleted the node_modules directory and ran npm i and I can run the app again. Consistently if yarn touches the node_modules the error will return.

BYK commented 7 years ago

@PolGuixe @victoriafrench can you please try this with https://5243-49970642-gh.circle-artifacts.com/0/home/ubuntu/yarn/artifacts/yarn-1.0.2.js

It has an important fix regarding peer dependencies and may help you.

BYK commented 7 years ago

If it doesn't solve your problem, can you share reproduction steps, including a package.json file at least that demonstrates the problem.

PolGuixe commented 7 years ago

@BYK do you mean updating to the latest yarn?

BYK commented 7 years ago

@PolGuixe nope, that link is to a PR/nightly build which is not released yet. Since that PR is merged now you can also try the nightly: https://yarnpkg.com/en/docs/nightly

darknoon commented 6 years ago

@BYK Having the same issue, even with the latest nightly:

$ yarn --version
1.1.0-20170929.1351

Is the resolution still to install the nightly?


$ react-native info
/Users/andrew/Code/Lobe/lobe/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: /Users/andrew/Code/Lobe/lobe/node_modules/react-native/local-cli/core/index.js: Unexpected token (29:2)
  27 | 
  28 | export type RNConfig = {
> 29 |   ...ConfigT,
     |   ^
  30 |   /**
  31 |    * Returns an array of project commands used by the CLI to load
  32 |    */
    at Parser.pp$5.raise (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp.unexpected (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:1716:8)
    at Parser.pp$3.parseIdentifier (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:4251:10)
    at Parser.pp$8.flowParseObjectPropertyKey (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5169:90)
    at Parser.pp$8.flowParseObjectType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5283:26)
    at Parser.pp$8.flowParsePrimaryType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5462:19)
    at Parser.pp$8.flowParsePostfixType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5580:19)
    at Parser.pp$8.flowParsePrefixType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5597:17)
    at Parser.pp$8.flowParseAnonFunctionWithoutParens (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5602:20)
    at Parser.pp$8.flowParseIntersectionType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5617:19)
darknoon commented 6 years ago

I was able to get it working by installing react-native's dependencies manually: $ pushd node_modules/react-native/; npm i; popd

BYK commented 6 years ago

We have released another set of peer dependency fixes with Yarn 1.2.1 and I cannot reproduce this right now on latest master. Can you confirm that 1.2.1 solves the issues or provide us with sample reproduction repo?

darknoon commented 6 years ago

@BYK I just tried this again on 1.2.1 and I'm getting the exact same issue. (I deleted node_modules after upgrading)

~/Code/Lobe/lobe (pin-yarn-version u+1) $ yarn
yarn install v1.2.1
~/Code/Lobe/lobe (pin-yarn-version u+1) $ react-native
/Users/andrew/Code/Lobe/lobe/node_modules/babel-core/lib/transformation/file/index.js:590
      throw err;
      ^

SyntaxError: /Users/andrew/Code/Lobe/lobe/node_modules/react-native/local-cli/core/index.js: Unexpected token (29:2)
  27 | 
  28 | export type RNConfig = {
> 29 |   ...ConfigT,
     |   ^
  30 |   /**
  31 |    * Returns an array of project commands used by the CLI to load
  32 |    */
    at Parser.pp$5.raise (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp.unexpected (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:1716:8)
    at Parser.pp$3.parseIdentifier (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:4251:10)
    at Parser.pp$8.flowParseObjectPropertyKey (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5169:90)
    at Parser.pp$8.flowParseObjectType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5283:26)
    at Parser.pp$8.flowParsePrimaryType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5462:19)
    at Parser.pp$8.flowParsePostfixType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5580:19)
    at Parser.pp$8.flowParsePrefixType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5597:17)
    at Parser.pp$8.flowParseAnonFunctionWithoutParens (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5602:20)
    at Parser.pp$8.flowParseIntersectionType (/Users/andrew/Code/Lobe/lobe/node_modules/babylon/lib/index.js:5617:19)
~/Code/Lobe/lobe (pin-yarn-version u+1) $ which react-native
node_modules/.bin/react-native
darknoon commented 6 years ago

OK, I think this is some kind of interaction with the babel version.

I ran yarn upgrade-interactive --latest and selected babel-jest, babel-preset-env, and babel-preset-react-native to upgrade.

I'm going to see if I can narrow down what package upgrade caused it to start working.

diff --git a/package.json b/package.json
index 2a8e762..3719fbc 100644
--- a/package.json
+++ b/package.json
@@ -49,16 +49,16 @@
        "autoprefixer": "^6.5.4",
        "babel-cli": "^6.26.0",
        "babel-eslint": "^7.2.3",
-       "babel-jest": "^21.0.2",
+       "babel-jest": "^21.2.0",
        "babel-loader": "^7.1.2",
        "babel-plugin-transform-async-generator-functions": "^6.24.1",
        "babel-plugin-transform-class-properties": "^6.24.1",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-polyfill": "^6.26.0",
-       "babel-preset-env": "^1.6.0",
+       "babel-preset-env": "^1.6.1",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-react": "^6.24.1",
-       "babel-preset-react-native": "^3.0.2",
+       "babel-preset-react-native": "^4.0.0",
        "babel-preset-stage-0": "^6.24.1",
        "babel-preset-stage-2": "^6.24.1",
        "babel-register": "^6.26.0",
darknoon commented 6 years ago

It looks like this might be fixed on the react-native side in 0.50.0-rc.1:

~/Code/Lobe/lobe (development * u=) $ yarn add react-native@0.50.0
~/Code/Lobe/lobe (development * u=) $ react-native
Scanning folders for symlinks in /Users/andrew/Code/Lobe/lobe/node_modules (25ms)

  You didn't pass any command
  Run react-native --help to see list of all available commands

Still, it seems like there might be a yarn bug if the behavior differs significantly from npm and causes this.

chirag14252 commented 1 year ago

i have been getting this error on render.com while migration from npm to yarnyarn config v1.22.5 Aug 24 07:08:59 PM success Set "ignore-engines" to "true". Aug 24 07:08:59 PM Done in 0.04s. Aug 24 07:08:59 PM [1/4] Resolving packages... Aug 24 07:09:01 PM [2/4] Fetching packages... Aug 24 07:09:05 PM error mongodb@5.8.1: The engine "node" is incompatible with this module. Expected version ">=14.20.1". Got "14.17.0" Aug 24 07:09:05 PM error Found incompatible module. Aug 24 07:09:05 PM info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. Aug 24 07:09:05 PM ==> Build failed 😞