Search code examples
npmnode-modulesyarnpkgyarn-workspaces

When using yarn workspaces, how to force a package to be installed in the relative node_modules?


I love yarn workspaces, but more often than not I find myself having to pull out a specific package because of incompatibilities with external tools.

The main issue is that I don't have their source code in the relative node_modules, but a few levels above (which is normal for yarn workspaces and node, in general).

For instance, ZeppelinOS gives the following error message when "openzeppelin-eth" is not found in the relative path:

Could not find a zos.json file for 'openzeppelin-eth'. Make sure it is provided by the npm package.

Is there a way to force-copy a package? I read about --focus, but it's not what I need.


Solution

  • What you're looking for is called nohoist https://yarnpkg.com/blog/2018/02/15/nohoist/

    Basically you have two options:

    1. do it from the child package
    "workspaces": {
      "nohoist": ["react-native", "react-native/**"]
    }
    
    1. do it from the root level
    "workspaces": {
      "packages": ["packages/*"],
      "nohoist": ["**/react-native", "**/react-native/**"]
    }
    

    If you want to share package xyz among all your sub-projects, then set it in the root, otherwise in the child project.