Npm link and scoped packages

1.7k Views Asked by At

When running npm link (as per the multiple vague blog posts on the subject) on a private scoped packed, I am getting an E404 error.

This seems particularly odd considering the entire point of npm link is to sym-link local files. I do not understand why any request is being made.

Here are my commands;

$ cd /path/to/library
$ npm link
$ cd /path/to/my/project
$ npm link library

Which gives

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/library - Not found
npm ERR! 404 
npm ERR! 404  'library@*' is not in this registry.

Anyway, I don't want to link to node_modules/library, the actual library is node_modules/@scope/library, so I also tried (in the project folder)

$ npm link @scope/library

Which gives a similar error

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@scope/library - Not found
npm ERR! 404 
npm ERR! 404  '@scope/library@*' is not in this registry.

The scoped library is hosted on an internal repository, not the global npmjs repository, but I still don't understand why this request is being made since I want to link the local library changes to my local project.

Also, is there anything fundamentally different between using npm link and using ln -s myself?

1

There are 1 best solutions below

0
myol On

So npm link relies on the details within the package.json in the folder you initially run npm link

Typing npm -g list will show that the library is linked using the name and version in the package.json

$ npm -g list
/home/user/.npm-global/lib
├── @scope/[email protected] -> ./../../path/to/library

So the solution is simply to run the command with the name given in the global npm install list

$ npm link @scope/library-name-in-package-json