NPM doesn't install module dependencies

Npm

Npm Problem Overview


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"

Npm Solutions


Solution 1 - Npm

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:

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.

Solution 2 - Npm

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

Solution 3 - Npm

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.

Solution 4 - Npm

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.

Solution 5 - Npm

Also check that your package name is correctly accepted:

WRONG:

{
    "name": "My Awesome Package"
}


CORRECT:

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

Solution 6 - Npm

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

After that just reinstall everything with npm install.

Solution 7 - Npm

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.

Solution 8 - Npm

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.

Solution 9 - Npm

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!

Solution 10 - Npm

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: https://stackoverflow.com/a/16456467/241294

Solution 11 - Npm

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.

Solution 12 - Npm

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.

Solution 13 - Npm

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

Solution 14 - Npm

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!

Solution 15 - Npm

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.

Solution 16 - Npm

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.

Solution 17 - Npm

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 https://riptutorial.com/node-js/example/10101/setting-node-env--production- "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."

Solution 18 - Npm

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.

Solution 19 - Npm

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 : https://www.npmjs.com/ Example:

"dependencies": {
    "express": "4.17.1",
    "xyz": "git+https://github.com/bar/xyz.git"
}

If the package xyz is hosted correctly on www.npmjs.com 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: https://stackoverflow.com/questions/54124033/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+https://github.com/bar/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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAhmed NuamanView Question on Stackoverflow
Solution 1 - NpmallprogView Answer on Stackoverflow
Solution 2 - NpmMohsenView Answer on Stackoverflow
Solution 3 - NpmVirat18View Answer on Stackoverflow
Solution 4 - NpmRico Rodriquez CollinsView Answer on Stackoverflow
Solution 5 - NpmCaiusView Answer on Stackoverflow
Solution 6 - NpmLars KliesingView Answer on Stackoverflow
Solution 7 - NpmNrjView Answer on Stackoverflow
Solution 8 - NpmkctangView Answer on Stackoverflow
Solution 9 - NpmcafesanuView Answer on Stackoverflow
Solution 10 - NpmpoidaView Answer on Stackoverflow
Solution 11 - NpmdgoView Answer on Stackoverflow
Solution 12 - NpmAhmed FathyView Answer on Stackoverflow
Solution 13 - NpmDekeView Answer on Stackoverflow
Solution 14 - NpmJesse LawsonView Answer on Stackoverflow
Solution 15 - NpmmansimView Answer on Stackoverflow
Solution 16 - NpmVainqueurView Answer on Stackoverflow
Solution 17 - NpmAbdallahView Answer on Stackoverflow
Solution 18 - NpmJames MascarenhasView Answer on Stackoverflow
Solution 19 - NpmJRichardszView Answer on Stackoverflow