Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npx create-react-app throws error when using in monorepo #5195

Open
FelixKuehl opened this issue Oct 1, 2018 · 5 comments
Open

npx create-react-app throws error when using in monorepo #5195

FelixKuehl opened this issue Oct 1, 2018 · 5 comments

Comments

@FelixKuehl
Copy link

FelixKuehl commented Oct 1, 2018

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:

{ 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! ;)

@Timer Timer added this to the 2.0.x milestone Oct 1, 2018
@Timer
Copy link
Contributor

Timer commented Oct 1, 2018

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

@weyert
Copy link
Contributor

weyert commented Oct 3, 2018

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

@FelixKuehl
Copy link
Author

FelixKuehl commented Oct 3, 2018

@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: #5100

Hope that helps!

@bradfordlemley
Copy link
Contributor

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

@weyert
Copy link
Contributor

weyert commented Oct 18, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants