Create-react-app: npx create-react-app throws error when using in monorepo

Created on 1 Oct 2018  路  5Comments  路  Source: facebook/create-react-app

Is this a bug report?

Maybe.
I know monorepos are not fully supported, however i would expect this to work.

Did you try recovering your dependencies?

Yes

Environment


Node v8.11.3
yarn 1.10.1
npx 6.4.1

Steps to Reproduce

(Write your steps here:)

  1. Create a lerna / yarn workspaces repo
  2. naviagte to packages folder
  3. run create-react-app@next --scripts-version=@next cra-app

Expected Behavior

It should create a new create react app.

Actual Behavior


When running create-react-app@next --scripts-version=@next cra-app, I am getting the following error:
Unexpected error. Please report it as a bug: { Error: Cannot find module '/Users/felixkuehl/cra-monorepo/packages/cra-app/node_modules/react-scripts/package.json' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at checkNodeVersion (/Users/felixkuehl/.npm/_npx/66044/lib/node_modules/create-react-app/createReactApp.js:543:23) at getPackageName.then.then.then.packageName (/Users/felixkuehl/.npm/_npx/66044/lib/node_modules/create-react-app/createReactApp.js:344:7) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) code: 'MODULE_NOT_FOUND' }
This could maybe due to yarn workspaces package hoisting.

Workaround is to just run create-react-app@next --scripts-version=@next cra-app outside the monorepo, then delete the node_modules folder and copy the new app into the monorepo.
Anyways, keep up the great work! ;)

bug

Most helpful comment

@weyert Check out my example repo https://github.com/FelixKuehl/cra-monorepo
In this setup I am using a Create React App 2.x together with a library to share components. I build a package in this monorepo called library-utils, that provides a custom babel watcher and handles basic setup to compile every package in your monorepo, if needed. So every create react app can be used as a library by simply adding 'build:watch': 'library-utils build:watch' to it's scripts (Do not forget to specify main and module as well).
The library is compiled and watched by babel. This works pretty well for me and basically behaves just as well as the original monorepo support in CRA 2. At least for my use case.

If you need more details, take a look at the readme in my repo and checkout my original Issue regarding dropped monorepo support in CRA 2 stable: https://github.com/facebook/create-react-app/issues/5100

Hope that helps!

All 5 comments

Yeah, we can probably fix this. For now, just use your workaround. Thanks for the report!

May I ask how you created the mono repo? I have been trying to share some ui components between two projects using a mono repo. Only I haven't been able to get it working: https://github.com/weyert/monorepo

Does anyone know a good example of CRA2 with code sharing? I can find a bunch of repos on Github but they seem to depend on the now dropped monorepo support in CRA2

@weyert Check out my example repo https://github.com/FelixKuehl/cra-monorepo
In this setup I am using a Create React App 2.x together with a library to share components. I build a package in this monorepo called library-utils, that provides a custom babel watcher and handles basic setup to compile every package in your monorepo, if needed. So every create react app can be used as a library by simply adding 'build:watch': 'library-utils build:watch' to it's scripts (Do not forget to specify main and module as well).
The library is compiled and watched by babel. This works pretty well for me and basically behaves just as well as the original monorepo support in CRA 2. At least for my use case.

If you need more details, take a look at the readme in my repo and checkout my original Issue regarding dropped monorepo support in CRA 2 stable: https://github.com/facebook/create-react-app/issues/5100

Hope that helps!

3967 is a fix for this issue, but it needs to be rebased.

Thanks @FelixKuehl I am going to have a closer look at your repo :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oltsa picture oltsa  路  3Comments

alleroux picture alleroux  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

Aranir picture Aranir  路  3Comments