Skip to content

Usage with yarn workspaces #2

@teevik

Description

@teevik

The 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;
}

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions