You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use CRA to create a new yarn workspace/package #3405
A new CRA application to be initialized under packages/app-a
Actual Behavior
...
Aborting installation.
Unexpected error. Please report it as a bug:
{ Error: Cannot find module '/Users/cra/Projects/sandbox/repro/packages/workspace-a/node_modules/react-scripts/package.json'
at Function.Module._resolveFilename (module.js:527:15)
at Function.Module._load (module.js:476:23)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at checkNodeVersion (/Users/cra/.config/yarn/global/node_modules/create-react-app/createReactApp.js:488:23)
at getPackageName.then.then.then.packageName (/Users/cra/.config/yarn/global/node_modules/create-react-app/createReactApp.js:295:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) code: 'MODULE_NOT_FOUND' }
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting workspace-a / from /Users/cra/Projects/sandbox/repro/packages
Done.
@gaearon I tried to use require.resolve within the current path.resolve but couldn't get it working... granted I only had a couple of minutes to try, so I may not have used it right... feels like it should be an easy fix though - to get the script to use node's require resolution algorithm.
@dariocravero - thats the workaround I've gone with, creating in a tmp location and copying into the yarn workspaces structure. In addition to removing node_modules, you may want to also remove yarn.lock as I believe with workspaces all package locks are managed in the top-level lockfile? I could be mistaken though, I came to this conclusion when running yarn outdated in the repo root and having outdated dependencies inside nested packages appearing in the output. @gaearon - does that sound right?
Activity
gaearon commentedon Nov 3, 2017
Yea, we should really figure out a Workspaces integration. Also as a solution to the "absolute imports" problem.
mattfysh commentedon Nov 3, 2017
@gaearon I tried to use
require.resolvewithin the currentpath.resolvebut couldn't get it working... granted I only had a couple of minutes to try, so I may not have used it right... feels like it should be an easy fix though - to get the script to use node'srequireresolution algorithm.PS. Thanks for the quick reply! 🚀
dariocravero commentedon Dec 2, 2017
In case anyone is stuck with this and until the different issues are fixed, I made a little guide on how to use yarn workspaces with Create React App and Create React Native App (Expo) to share common code across. Hope you find it handy!
https://learn.viewsdx.com/how-to-use-yarn-workspaces-with-create-react-app-and-create-react-native-app-expo-to-share-common-ea27bc4bad62https://medium.com/viewsdx/how-to-use-yarn-workspaces-with-create-react-app-and-create-react-native-app-expo-to-share-common-ea27bc4bad62mattfysh commentedon Dec 4, 2017
@dariocravero - thats the workaround I've gone with, creating in a tmp location and copying into the yarn workspaces structure. In addition to removing node_modules, you may want to also remove yarn.lock as I believe with workspaces all package locks are managed in the top-level lockfile? I could be mistaken though, I came to this conclusion when running
yarn outdatedin the repo root and having outdated dependencies inside nested packages appearing in the output. @gaearon - does that sound right?dariocravero commentedon Dec 4, 2017
That's a good point @mattfysh, thanks! Updated the guide :)
gaearon commentedon Jan 8, 2018
Seems like a duplicate of #3031.