Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't install dependencies when one of them is linked from global #3584

Open
owl-from-hogvarts opened this issue Jul 6, 2021 · 11 comments
Open
Projects

Comments

@owl-from-hogvarts
Copy link

pnpm version: 6.9.1

Steps to reproduce the issue:

  1. make two packages (e.g. one and second)
  2. link one package to global (pnpm link --global) and then link it to second (from second's directory run pnpm install --global one)
  3. by hand add to package.json some dependency from npm registry e.g. react
  4. try pnpm i

Expected behavior:

Dependencies fron npm registry are installed.

Actual behavior:

myown-package is linked to /path/to/antoher/package/node_modules from /path/to/package/myown-package
 ERROR  GET https://registry.npmjs.org/myown-package: Not Found - 404
myown-package is not in the npm registry, or you have no permission to fetch it.

Additional information:

  • node -v prints: v14.15.3
  • Windows, macOS, or Linux?: Manjaro KDE
@rahulkandikatla
Copy link

rahulkandikatla commented Aug 4, 2021

Is myown-package getting added in dependencies of project's package.json?

Can you once check in these lines also.. I am also facing the same issue

@owl-from-hogvarts
Copy link
Author

@rahulkandikatla Yes it is. And it is a important point here. I guess pnpm has wrong priority adjustments: it is first looks to npm registry and only then (if at all) looks to global directory for packge linking. My thoughts is that pnpm just fail on first error instead of trying other variants (global packages in this case).

@cpakken
Copy link

cpakken commented Dec 4, 2021

pnpm package.json should clearly indicate when a package is linked or when it's from a repository.
Similar to adding a workspace package will result in:

"@my-workspace/core": "workspace:^0.0.1",

Packages added by linking should indicate:

"@my-linked-package/core": "link:^0.0.1",

Then pnpm should handle linked packages similar to workspace packages like skipping install command.

@specious
Copy link

If I link a package from a local directory with:

pnpm link <dir>

Then it is listed in the pnpm-lock.yaml file with a link: prefix.

If I then do:

pnpm up

After that there is no trace of it being linked.

@specious
Copy link

Maybe pnpm should simply check if the package in node_modules/ is symlinked to a local directory, and in that case not touch that dependency during upgrading.

@gouldingken
Copy link

Maybe pnpm should simply check if the package in node_modules/ is symlinked to a local directory, and in that case not touch that dependency during upgrading.

After giving more thought to how this feature would be used, I completely agree with this idea of checking in 'node_modules' for symlinks - rather than any kind of modifications to the package.json (e.g. link: syntax).

IMO it should be up to each individual developer whether they are using a locally linked package (via pnpm link -g xxx) or pulling the package from npm. If a dev working on an external package uses a locally linked package - this should not impact other devs and require them to also use a link (as would be suggested by modifications to package.json).

@gouldingken
Copy link

This is not an elegant solution, but while we wait on a fix for this bug, here's a workaround that may help someone: https://gist.github.com/gouldingken/332abc5f95a9e59c685cb15461b698e1

@isaac-mcfadyen
Copy link

Is there any timeline on this issue being fixed?

For me it's a fairly major blocker for development using local packages right now...

@AlansCodeLog
Copy link

What I ended up doing was making a script to regular link my local packages (the list of linkable packages is set by an env variable). This will run any prepare scripts in the linked packages (and I think postinstall too?), unlike linking via a global link but it works without modifying any packages.

https://gist.github.com/AlansCodeLog/770d80bc7e51d264970dff75cb04ffc6

@sannajammeh
Copy link

Workaround without postinstall - MacOS

I'm sure this is doable on windows and linux as well.

  1. Get global link folder, this should be printed once you run pnpm link --global
  2. In your app use this format
link:/Users/<user>/Library/pnpm/global/5/node_modules/<library>
  1. Final package.json should look like this
{
  "dependencies": {
    "<lib>": "link:/Users/<user>/Library/pnpm/global/5/node_modules/<lib>"
  }
}

This should allow pnpm to install other deps. Works for me at least.

@aolyang
Copy link

aolyang commented Aug 9, 2023

In pnpm way what I did is:
with @scope/my-lib not publish yet. (project and lib is parallel by the way)

"dependencies": {
+  "@scope/my-lib": "link:../path-to-my-libs/packages/my-lib"
}

CI/CD handle local lib part too.
once my lib published:
pnpm add @scope/my-lib

"dependencies": {
-  "@scope/my-lib": "link:../path-to-my-libs/packages/my-lib"
+  "@scope/my-lib": "^0.0.1"
}

while local developing (my-lib):

# link to global node_modules
workspaces/my-lib >pnpm link --global
# link to local
workspaces/my-project> pnpm link  --global @scope/my-lib

This is ok for me, for one or two packages, but it does has more packages developed in local, and published into private registry.

In conclusion, there maybe has a way to simplify the pipe (in my humble opinion):

while link the local lib pnpm link --global, pnpm global rcfile (~/.npmrc or else) will add this line:

+@scope/my-lib=pnpm-link:../path-to/my-lib

Then, project install from the path automaticlly, the lib package version flag can keep in package.json and output log:

pnpm links several packages:
@scope/my-lib@^0.0.1 <- path-to/my-lib
"dependencies": {
+  "@scope/my-lib": "^0.0.1"
}

if link the local lib is a misstake, developer should manully unlink:

> pnpm unlink --global @scope/my-lib # or unlink in lib local directory
- @scope/my-lib is droped from global node_modules

if there is somthing wrong or features I missed, fell free to comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Priority
Status
Priority
Development

No branches or pull requests

9 participants