Yarn: Proposal: use symlink to whole node_modules folder in workspaces

Created on 7 Feb 2018  路  3Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

Improvement for existing feature

What is the current behavior?

When using workspaces, all node modules are located in a single node_modules folder in the root of a project. Nested packages are able to reference to installed dependencies due to the way how Node.js resolves imports, basically looking at parent folders for node_modules. When a nested package (workspace) depends on a tool with CLI, Yarn creates symlinks to .bin folder files from the root modules folder.

What is the expected behavior?

Several tools (i.e. https://github.com/facebook/create-react-app/issues/3031, https://github.com/facebook/flow/issues/5107) need additional work to be done to support workspaces which breaks user experience when they trying to adopt workspaces in their projects. I can imagine even more tools have possible issues with workspaces, either not discovered or not reported yet.

Current proposal is to make symlink to whole node_modules folder in workspaces, instead of just symlinking CLIs. In this way, zero tools would need to make additional changes only in favor of supporting workspaces. It immediately allows the use of Flow and CRA (current versions) with workspaces.

Please mention your node.js, yarn and operating system version.

I use Yarn 1.3.2 with Node.js 8.9 on macOS 10.12.

triaged

Most helpful comment

I am facing the following issue. I guess its related.

Lets say I have my directory structure as follows

- project
   - lib (a common library package)
       - package.json
   - workspace-1
       - package.json (has workspace dependency: "lib": "./lib")

With Yarn install its doing two things.

  1. Creates symlinks in node_modules under main project directory. [ EXPECTED ]
  2. Copies lib directory inside workspace-1/node_modules (not symlink) [ NOT EXPECTED ]

And so any change I do in lib isn't reflected in workspace-1.
I have to delete the workspace level packages for it to work as expected.

Expectation:
I guess it isn't required to place the workspace dependencies under sub directory node_modules.
Even if it is the case for some reason they should be symlinked.

All 3 comments

I am facing the following issue. I guess its related.

Lets say I have my directory structure as follows

- project
   - lib (a common library package)
       - package.json
   - workspace-1
       - package.json (has workspace dependency: "lib": "./lib")

With Yarn install its doing two things.

  1. Creates symlinks in node_modules under main project directory. [ EXPECTED ]
  2. Copies lib directory inside workspace-1/node_modules (not symlink) [ NOT EXPECTED ]

And so any change I do in lib isn't reflected in workspace-1.
I have to delete the workspace level packages for it to work as expected.

Expectation:
I guess it isn't required to place the workspace dependencies under sub directory node_modules.
Even if it is the case for some reason they should be symlinked.

yarn 1.5.1 just released the new feature nohoist, which should be able to make react and react-native experience much simpler. Feel free to give it a try. examples available here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MunifTanjim picture MunifTanjim  路  3Comments

ocolot picture ocolot  路  3Comments

chiedo picture chiedo  路  3Comments

catkins picture catkins  路  3Comments

NonPolynomial picture NonPolynomial  路  3Comments