Usage with yarn workspaces
See original GitHub issueThe error:
$ yarn run dev
yarn run v1.10.1
$ craco start
module.js:549
throw err;
^
Error: Cannot find module 'C:\WebDev\coding-tracker\packages\client\node_modules\react-scripts/config/paths.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.resolve (internal/module.js:18:19)
at resolveConfigFilePath (C:\WebDev\coding-tracker\node_modules\@craco\craco\lib\cra.js:24:20)
at Object.<anonymous> (C:\WebDev\coding-tracker\node_modules\@craco\craco\lib\cra.js:38:26)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I’m using yarn workspaces for a monorepo, so all the node_modules is shared in a single folder. My app has a structrue like this:
coding-tracker/
├── node_modules/
└── packages/
├── api/
├── shared/
└── client/
Now the problem is that craco looks for the react-scripts files in coding-tracker/packages/client/node_modules
instead of coding-tracker/node_modules
I’m pretty sure that’s because process.cwd()
would be coding-tracker/packages/client
: https://github.com/sharegate/craco/blob/master/packages/craco/lib/paths.js#L4
I made a quick workaround in my case by doing this:
function getReactScriptsFolderPath() {
- let filepath = "";
+ let filepath = "react-scripts";
- if (args.reactScripts.isOverrided) {
- filepath = path.resolve(`${projectRoot}/${args.reactScripts.value}/`);
- } else {
- filepath = path.resolve(`${nodeModulesPath}/react-scripts/`);
- }
log("Found react scripts folder at: ", filepath);
return filepath;
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >Yarn workspaces — monorepo beginner's guide - Medium
Yarn Workspaces is a feature that allows users to install dependencies from multiple package.json files in subfolders of a single root package.json file,...
Read more >Yarn Workspaces: Organize Your Project's Codebase Like A Pro
Yarn workspaces let you organize your project codebase using a monolithic repository (monorepo). The idea is that a single repository would ...
Read more >Scaling out JavaScript Monorepos with Yarn Workspaces
The first thing to do is set up the workspaces. Start by ensuring that you're running the latest Yarn version. ... Next, initialize...
Read more >Why should you use yarn workspaces? - DEV Community
The Solution · It sets up a single node_modules without repetitions. · It allows you to change the code of one of your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yes, https://github.com/axelchalon/craco-issue
Notice how
yarn start
works butyarn test
doesn’t.Some observations: tests work if there is only one test file, and tests work if I remove
babel: {...}
from the export ofcraco.config.js
Can confirm
craco {test,build,start}
all work fine with craco v4.0.0 and specifyingreactScriptsPath
in craco.config.js 👍 thank you!