Skip to content

react-native init not working with yarn workspaces #24202

@Grohden

Description

@Grohden

Since all the other bug reports (#23175, #16666) seems to be closed by not following the issue template, i'm opening this one.

🐛 Bug Report

I'm using react-native init to create a simple app inside a monorepo, but the cli seems to have problems with the yarn workspaces (with hoisting) - I'm also using lerna, but i don't think that lerna is causing the problems here.

To Reproduce

I'm just running:
react-native init KeepfyApp

The log is:

This will walk you through creating a new React Native project in /home/gabriel/keepfy/root/packages/KeepfyApp
Using yarn v1.15.2
Installing react-native...
yarn add v1.15.2
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
**========= SOME WARNINGS NOT INCLUDED HERE =========**
[4/4] Building fresh packages...

success Saved 1 new dependency.
info Direct dependencies
info All dependencies
└─ react-native@0.59.2
Done in 12.57s.
internal/modules/cjs/loader.js:651
    throw err;
    ^

Error: Cannot find module '/home/gabriel/keepfy/root/packages/KeepfyApp/node_modules/react-native/package.json'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:649:15)
    at Function.Module._load (internal/modules/cjs/loader.js:575:25)
    at Module.require (internal/modules/cjs/loader.js:705:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at checkNodeVersion (/home/gabriel/.fnm/node-versions/v11.12.0/installation/lib/node_modules/react-native-cli/index.js:306:21)
    at run (/home/gabriel/.fnm/node-versions/v11.12.0/installation/lib/node_modules/react-native-cli/index.js:300:3)
    at createProject (/home/gabriel/.fnm/node-versions/v11.12.0/installation/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/home/gabriel/.fnm/node-versions/v11.12.0/installation/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/home/gabriel/.fnm/node-versions/v11.12.0/installation/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (internal/modules/cjs/loader.js:799:30)

The Error: Cannot find module '/home/gabriel/keepfy/root/packages/KeepfyApp/node_modules/react-native/package.json' is correct, there's no node_modules folder there, they are installed in the root folder, the correct path should be /home/gabriel/keepfy/root/node_modules/react-native/package.json

Expected Behavior

I'm expecting the app to be created, but only the package.json is created.

Code Example

// lerna.json
{
  "packages": [
    "packages/*"
  ],
  "npmClient": "yarn",
  "useWorkspaces": true,
  "version": "independent"
}

//package.json (root)
{
  "name": "root",
  "private": true,
  "devDependencies": {
    "lerna": "3.13.1",
    "yarn": "1.15.2"
  },
  "workspaces": [
    "packages/*"
  ],
  "scripts": {
    "build": "lerna run build --stream",
    "bootstrap": "lerna bootstrap"
  }
}

With those files in a root project folder, run cd packages && react-native init and you should see the error.

There's something to note here, i could start a ''correct'' project only once, react-native init created the folder and stuff inside, but it installed ignoring the yarn workspaces (because it created the yarn.lock inside the app folder).. so i think that time doesn't count.

Environment

[skip envinfo]

Ran inside the created folder KeepfyApp:
react-native info ->

Command `info` unrecognized. Make sure that you have run `npm install` and that you are inside a react-native project.

react-native --version ->

react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory

If there's another info i can provide to help just ask.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions