Yarn: `file:` dependencies in workspaces

Created on 1 May 2018  路  12Comments  路  Source: yarnpkg/yarn

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

Bug.

What is the current behavior?

Having a dependency with file: specifier leads to copying it into the node_modules folder. Having a version specifier 1.0.0 makes it a symlink.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

npm staring from 5.0 automatically creates symlinks for file:. It makes a lot of sense, especially for monorepos. I didn't found any info why this behavior was chosen for yarn, so I assume it's a bug.

Also, paths in lock-file for dependencies with file: look like ../../../yarn/cache/v1/package-name. Seems another bug.

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

yarn: 1.6.0
needs-discussion triaged

Most helpful comment

But the link: protocol doesn't work with npm. So, I will not be able to run npm install. And I suppose that yarn should be backward compatible in this particular case.

All 12 comments

We have chosen to keep the old file: behavior since we already have workspaces and the link: protocol support so this is not a bug.

Having a version specifier 1.0.0 makes it a symlink.

Your description is not clear around when this happens but if this is when the package is defined as a workspace, it also is expected. file: is always copied whereas versions are tried to be resolved from the workspace at first as links and then from the registry as normal packages.

Also, paths in lock-file for dependencies with file: look like ../../../yarn/cache/v1/package-name. Seems another bug.

This is a bug but since we always copy things to cache from the source, it doesn't affect anything.

But the link: protocol doesn't work with npm. So, I will not be able to run npm install. And I suppose that yarn should be backward compatible in this particular case.

@BYK I totally agree with @the-spyke we need backward compatibility. Please add npm compatibility for file:. I can't use yarn because of that issue

I agree that using file: should result in the exact same node_modules as npm. This is a blocker for us to adopt yarn in our project as we use the file: protocol to symlink our own local packages. link: support is nice (I discovered it here; it doesn't seem to be mentioned in the documentation), but then package.json becomes incompatible with npm, which is a big deal, and I think against the "backwards compatible" mission of yarn (as I understand it).

yarn should be backward compatible with file:, suggested.

馃憢 I'd like to add that this is also a blocker for my company's adoption of yarn.
We are trying to shift to a monorepo architecture with yarn.. link: works but it's not standard with npm 鈽癸笍

I think nowadays, you just use yarn or npm - not both. It's a technical decision you make when putting the project tech stack together.

Having said that, it would be nice to have yarn compatible with file:.

Unfortunately, I'm working on a different project now and don't remember exactly why did I need this.

But if you need to have a local copy of some package (like a modified version), you may just add its folder as a workspace. In this case it will be symlinked to the node_modules root and used in all other packages.

Also, I've tried to add a file:./package.tgz and file:./folder deps and yarn.lock shows right paths pointing to the my repo and not to the cache as it was before. So, maybe this ticket should be closed.

I'm closing this issue for the sake of transparency as we have no intentions to change this behavior. The major reason is workspaces already providing the requested behavior as others mentioned above.

@BYK There seems to be no way to use workspaces when you need at the same time:

  • monorepo
  • private packages (never published on a registry)
  • deploy in production each package as if it were in it's own repository/folder without using workspaces (something like yarn install --prod that totally ignores the workspace and installs everything in node_modules)
  • need to have a yarn.lock file for each package

@BYK Unfortunately this issue is not resolved when using the file protocol in the root package json.

When a single file protocol is used, the symlink is created

root package.json

"package1" : "file:./packages/package1"
"package2" : "latest"

Symlink to package1 is created from node_modules/package1 -> packages/package1

But when I use a file protocol with package2 as well.

"package1" : "file:./packages/package1"
"package2" : "file:./packages/package2"

No symlinks are created. This is very odd.

link does not work from project root either

Dear @dan-cooke and @aalexgabi,

Your issues seem to be somewhat related but more specific. Please file new issues with clear reproduction steps, preferably with programmatic reproduction like a sample repo we can pull and run yarn install to observe the behavior.

I'll lock this issue to prevent further new/similar reports.

Was this page helpful?
0 / 5 - 0 ratings