question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use a CRA project inside Yarn Workspaces

See original GitHub issue

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

I am using npm 4.6.1 and its a yarn specific bug anyways.

Which terms did you search for in User Guide?

I simply searched the github repo for workspace and yarn workspace I didn’t see a relevant error message/issue.

Environment

  1. node -v: 8.4.0
  2. npm -v: 4.6.1
  3. yarn --version: 0.27.5
  4. npm ls react-scripts: Empty (no scripts to use)

Then, specify:

  1. Operating system: OSX El Capitan 10.11.6

Steps to Reproduce

https://github.com/thomas-jeepe/err-demo

  1. mkdir err-demo
  2. cd err-demo
  3. touch .yarnrc
  4. echo "workspaces-experimental true" > .yarnrc
  5. touch package.json
  6. Write
{
  "name": "meme",
  "version": "1.0.0",
  "main": "index.js",
  "private": true,
  "workspaces": ["packages/*"]
}

to package.json 7. mkdir packages 8. cd packages 9. create-react-app test

Or: https://github.com/thomas-jeepe/err-demo/

Expected Behavior

create-react-app would use the tools installed at the workspace level.

Actual Behavior

Doesn’t find the tools and just complains:

Aborting installation.
Unexpected error. Please report it as a bug:
{ Error: Cannot find module '/Users/PenguinSoccer/code/js/err-demo/packages/test/node_modules/react-scripts/package.json'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at checkNodeVersion (/Users/PenguinSoccer/.config/yarn/global/node_modules/create-react-app/createReactApp.js:476:23)
    at getPackageName.then.then.then.packageName (/Users/PenguinSoccer/.config/yarn/global/node_modules/create-react-app/createReactApp.js:285:7)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) code: 'MODULE_NOT_FOUND' } 

Reproducible Demo

https://github.com/thomas-jeepe/err-demo/

So, just using regular logic, it seems that create-react-app is unaware about yarn workspaces, which install at the package level node_modules rather than for each individual folder in the workspace.

create-react-app goes for the folder’s node_modules when the node_modules are kept in the workspace root.

Although from my understanding, yarn attempts to link node_modules in each directory to the root workspace, so then I don’t know what the issue is.

Whether create-react-app should support yarn workspaces is up to you guys and low priority for me, since I probably won’t use it anyway (think its a cool project though 😃)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:41
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

46reactions
fazouane-marouanecommented, Apr 8, 2018

Hi,

I’ve had this issue last month. Luckily a fix in yarn and a blog article had already been published https://yarnpkg.com/blog/2018/02/15/nohoist/

So the quick fix on my side was to update yarn to 1.4.2 or later then to add the following in the cra app’s package.json

"workspaces": {
  "nohoist": ["react-scripts", "react-scripts/**"]
}

or in the root package.json:

"workspaces": {
  "packages": ["packages/*"],
  "nohoist": ["**/react-scripts", "**/react-scripts/**"]
}
7reactions
MikeSuitercommented, May 17, 2018

@fazouane-marouane I created a small repo that has an app and library under packages. The app is trying to use a React component from the library and I put the error in the readme. Maybe it’s as simple as I’m importing Test incorrectly in App.js or have ** incorrect in the workspace package.json. Thanks for any help with this.

https://github.com/MikeSuiter/cra-yarn-workspace

Read more comments on GitHub >

github_iconTop Results From Across the Web

CRA and Yarn Workspace - Medium
Recently, I wanted to set up a Typescript Create React App (CRA)in a Yarn workspace for my pet projects. I have gone through...
Read more >
How to remove CRA from yarn workspaces? - Stack Overflow
When running yarn inside the create-react-app package, I want to install every dependency used from fooApp and sharedApp (this is a expected ...
Read more >
React Monorepo Using Yarn Workspaces Only (No Lerna)
The main module package reactjs-use-form is installed as a dependency. The craco config is as follows:
Read more >
Workspaces - Yarn
And that's it! Requiring workspace-a from a file located in workspace-b will now use the exact code currently located inside your project rather...
Read more >
Use Yarn Workspaces to Share Code with CRA and create ...
[00:56] Now that we have our shared code, let's create the other two projects. We're going to cd up to our packages. I'm...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found