Search code examples
javascriptnpmgulpyarnpkg

Run Yarn tasks from a parent directory


I have a project that contains several sub projects, one of which is a JavaScript project. I want to use the JavaScript project as a task runner for the entire project via gulp but I'm running into some trouble.

My project structure is essentially:

root 
     |_
       js-client 
                |_
                   package.json
                |_
                   node_modules
     |_
       go-server

I've determined that .yarnrc can be used to specify a different node_modules location, so I moved package.json to the root directory and created this .yarnrc file:

--modules-folder client/node_modules

Now when I run yarn install from the root directory, the modules do get installed exactly as I expect in the specified location but when I run yarn build I get this error:

[09:46:17] Local modules not found in ~/Documents/Projects/root
[09:46:17] Try running: npm install

I'm guessing this means --modules-folder is only used as a flag for install and not for run. Is what I'm trying to do possible, or do I just have to create a separate yarn project to run tasks? I'd rather not rely on global to accomplish this


Solution

  • The answer is to run yarn with --cwd

    This changes yarn's working directory to whatever you specify

    So for the example above, to run yarn build from the root directory, you would type:

    yarn --cwd js-client build