6

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: krypton-search@1.0.0

What am I doing wrong?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156

1 Answers1

5

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

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Okay! Excellent! That worked like a charm. It just wasn't self explanatory. – Alexis Wilke Dec 08 '18 at 03:02
  • 1
    @AlexisWilke Also, if you have a private Git repo (doesn't have to be GitHub), you can add it as a dependency as well. https://stackoverflow.com/a/28729646/362536 Use `git+ssh://` if hosted over SSH, or just the path for a local Git repo. – Brad Dec 08 '18 at 03:07