NPM doesn't install module dependencies

This is my package.json for the module that I'm including in the parent project:

{ "version": "0.0.1", "name": "module-name", "dependencies": { "express": "3.3.4", "grunt": "0.4.1", "grunt-contrib-compass": "0.4.0", "grunt-contrib-copy": "0.4.1", "grunt-contrib-cssmin": "0.4.1", "grunt-contrib-jshint": "0.6.3", "grunt-contrib-requirejs": "0.4.1", "grunt-contrib-uglify": "0.2.2", "grunt-contrib-watch": "0.5.1", "grunt-express-server": "0.4.1", "grunt-karma": "0.4.5", "grunt-regex-replace": "0.2.5", "request": "2.25.0" }, "scripts": { "postinstall": "grunt install" }
}

One thing to note is that this module is contained in a private repo and I include it in the parent package.json like: "module-name": "git+ssh://git@myserver:user/module-name.git"

3

19 Answers

It looks like you hit a bug that has existed for quite a while and doesn't have solution yet. There are several open issues for this case in the npm repository:

  • npm install should recursively check/install dependencies (closed)
  • local private module dependencies (closed)

In the first one people list several workarounds that you may try.

An alternative solution may be (a little hackish) to explicitly list the dependencies as first level dependents. This requires you to maintain the list but practically it has to be done very infrequently.

2

I had very similar issue, removing entire node_modules folder and re-installing worked for me. Learned this trick from the IT Crowd show!

rm -rf node_modules
npm install
8

I am using windows machine.

  1. I deleted node_modules folder.
  2. Somehow, package.lock.json file is getting created. I deleted that file.
  3. Then npm install.
  4. Clean build.
  5. Run.
2

if you inherited this code, it could be that the dependencies and versions were locked and you have a ./npm-shrinkwrap.json file.

if your dependency is not listed in that file, it will never get installed with the npm install command.

you will need to manually install the packages and then run npm shrinkwrap to update the shrinkwrap file.

2

Also check that your package name is correctly accepted:

WRONG:

{ "name": "My Awesome Package"
}

CORRECT:
{ "name": "my-awesome-package-name"
}
5

In my case it helped to remove node_modules and package-lock.json.

After that just reinstall everything with npm install.

0

OP may be true for an older version of node. However, I faced the same with node 4.4.1 as well.

It very well may be linked to the node version you are using. Try to upgrade to a latest version. Certain dependencies don't load transitively if they are incompatible with node version.

I found this by running npm update.

After upgrading to latest version (4.4 -> 5.9); this got fixed.

0

I suspect you're facing the issue where your package.json file is not in the same directory as your Gruntfile.js. When you run your grunt xxx commands, you get error an message like:

Local Npm module "xxx" not found. Is it installed?

For now, the solution is:

  • Create package.json in the same directory as Gruntfile.js
  • Define the modules required by your grunt project
  • Execute npm install to load them locally
  • Now the required grunt command should work.

IMHO, it is sad that we cannot have grunt resolve modules loaded from a parent npm module (i.e. package.json in a parent directory within the same project). The discussion here seems to indicate that it was done to avoid loading "global" modules but I think what we want is loading from "my project" modules instead.

2

Worth to mention to make sure your dependencies should be in the dependencies part of your package.json (as opposed to devDependencies).

My issue was basically the same as OP:

  • installing a private repo (Let's call it repo1) via "module-name": "git+ssh://git@myserver:user/my-repo-name.git" in other repo(Let's call it repo2),
  • in repo2's node_modules, one package dependency from repo1 wasn't there.
  • My silly mistake!.. repo1 was listing that dependency in devDependencies instead of dependencies
  • Move the dependency in my repo1's package.json from devDependencies to dependencies
  • In my repo2, I removed my node_modules and package-lock.json, did npm install, an voilà!... dependency was there!
1

You might need to install the grunt-cli, try this before doing a npm install:

sudo npm install -g grunt-cli

That fixes the grunt does not exit for me, you'll also need a valid grunt file.

Source:

5

Just in case anyone is suffering from this predicament and happens to make the same asanine mistake that I did, here is what it was in my case. After banging my head against the wall for an hour, I realized that I had my json incorrectly nested, and the key "dependencies" was inside of the key "repository".
Needless to say, no errors were evident, and no modules were installed.

0

Another way to work this around is to add this into your module package.json scripts section

"preinstall": "npm install {Packages You depend on}"

what this will does is, it will install all packages needed by the module and you won't get that error.

happens with old node version. use latest version of node like this:

$ nvm use 8.0
$ rm -rf node_modules
$ npm install
$ npm i somemodule

edit: also make sure you save.
eg: npm install yourmoduleName --save

I was receiving this error when I installed a clean Node dev environment on windows.

To fix this, I went into my new project directory (that I just scaffolded with yo angular) and typed in two commands:

npm install -g grunt --save-dev

That will install the local grunt dependencies to your project. Next:

npm install

That will ensure all your (new) project dependencies are installed.

Tada!

I faced the issue when I was trying to create the first Angular application.

ng new angular-tour-of-heroes
cd angular-tour-of-heroes
ng serve --open

So every time I tried to compile the app I get the dependency error. Finally was able to resolve the issue after running

npm install -g @angular/cli@latest

After that ng serve command works without any error when I replicate the above steps for new project.

I had the same problem. But on the same machine one project had good package.json, where all my dependencies are successfully installed. And in another project my package.json dependencies were not installed no matter what i do. I just copied the package.json and pasted into that another project. And it worked! The difference i have found was only empty line at the start of file. Dont know or it influences anything, maybe some other problem. But the problem was only the package.json file.

I think that I also faced this problem, and the best solution I found was to look at my console and figure out the error that was being thrown. So, I read it carefully and found that the problem was that I didn't specify my repo, description, and valid name in my package.json. I added those pieces of information and everything was okay.

I've been hours trying to debug this issue and finally it was that I had the NODE_ENV= env variable set to "production".

From "When the NODE_ENV environment variable is set to 'production' all devDependencies in your package.json file will be completely ignored when running npm install."

fix

As @Monkpit said : Deleting package-lock.json and re-running npm install solved the issue for me. But don't forget to push the new package-lock.json*.

explanation

Don't download the inherit dependencies would be an awful issue and Nodejs don't have it.

The error is caused by an older package-lock.json caused for the use of libraries not hosted in the official repository : Example:

"dependencies": { "express": "4.17.1", "xyz": "git+"
}

If the package xyz is hosted correctly on and is added to package.json, the npm install will download correctly the xyz dependencies. If the package is special or is under development, you could have this problem.

This file package-lock.json is very important. If you delete it (as several answers advice) you could have another severe issues: Deleting `package-lock.json` to Resolve Conflicts quickly

Finally, if you have this kind of errors in which foo dependencies are not downloaded:

{ "name": "acme", "version": "1.0.0", "dependencies": { "foo": "git+" }
}
  • validate that in acme/node_modules don't exist the foo dependencies
  • Check the package.json of foo if the dependencies are coorectly added
  • delete the node_modules of your local project (acme in the example)
  • delete package-lock.json
  • run npm install
  • validate that in acme/node_modules exist the foo dependencies
  • push this renewed file package-lock.json to your git repository

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like