I am using npm link package --save
to create a local link to a globally installed package.
It correctly creates the link to the package (and would install it globally in case it were not already installed); but it fails to update the dependencies in package.json
.
What I am missing here?
According the npm docs, npm link
is not intended to change your package.json
. It creates symbolic links on your file system for a package.
This allows you to still reference a module by name, but have it pull from your local filesystem:
cd ~/projects/node-redis # go into the package directory
npm link # creates global link
cd ~/projects/node-bloggy # go into some other package directory.
npm link redis # link-install the package
If you actually intend to insert a file path in your package.json
, use npm install
instead:
npm install --save /path/to/package
Then you'll see a reference in package.json
file:
"dependencies": {
"local-package": "file:/path/to/package"
}
Though I highly recommend you use npm link
instead, as it makes your package.json
more portable. If you commit your changes with local file paths, it may become invalid on another system, or if you move around the files.
Update: Use npm-link-better
I created a little tool for this: npm-link-save
npm-link-save
npm-link
with--save
(or--saveDev
) to save the linked dependency in yourpackage.json
.You can also link multiple dependencies with this.
Install
npm i -g npm-link-save
Usage
npm-link-save express # or npm-links express npm-links -D express // links in devDependencies npm-links express morgan // multiple links
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With