Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent "npm install" or "npm remove" from deleting my personal package?

I want to have a node_modules/my-package/... environment for one of my libraries.

My package.json is considered valid. I has a name and a version and a few other fields:

(this is node-modules/my-paclage/package.json)
{
    "name": "my-package",
    "version": "1.0.0",
    ...
}

Then I wanted to add it to the package-lock.json file so npm knows about it. If you do not do that, an npm install ... or npm uninstall ... actually deletes the my-package folder I created under node-modules/....

So I decided to add the info in my package-lock.json, only I'm not able to make it work. All I added is the version like so:

(this is package-lock.json)
...
"dependencies": {
    ...
    "my-package": {
        "version": "1.0.0"
    }
    ...
}
....

Again, the syntax per se is correct. However, with that entry, when I try to do an npm install ... or npm uninstall ... it tells me:

error 404 Not Found: [email protected]

What am I doing wrong?

like image 478
Alexis Wilke Avatar asked Dec 08 '18 01:12

Alexis Wilke


People also ask

How do I prevent npm install from removing packages?

Using the --no-save will tell npm not to remove the package from your package. json , npm-shrinkwrap. json , or package-lock. json files.

Does npm install remove unused packages?

You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.

Does npm install remove node modules?

The npm install command will check your node_modules folder and remove packages that are not listed as a dependency in package.

Does npm install use package lock?

The package-lock. json file stores the version information of each installed package unchanged, and npm will use those package versions when running the npm install command.


1 Answers

NPM manages everything under node_modules/. You don't want to add anything there manually.

NPM also manages package-lock.json. It's not intended for you to modify.

To install your package, my-package, you want to use npm install. It will copy or symlink your package to node_modules/, and will write out the installed version to package-lock.json.

If your package is local and not published to NPM, you can use npm install /path-to-mypackage. See also: https://stackoverflow.com/a/8089029/362536

like image 109
Brad Avatar answered Oct 17 '22 00:10

Brad