Skip to content
This repository has been archived by the owner. It is now read-only.

npm install not installing dependencies listed in package.json file #17282

Closed
brett-east opened this Issue Jun 18, 2017 · 25 comments

Comments

Projects
None yet
@brett-east
Copy link

brett-east commented Jun 18, 2017

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

I am running npm install expecting it to install all the dependencies in my package.json file, and it is not. Despite having lodash in my package.json file, I am still getting an error 'cannot resolve lodash'. Then when I npm i lodash it works and that error goes away.

I couldn't see this in existing issues, or in the troubleshooting doc.

How can the CLI team reproduce the problem?

I initialised a project using Yarn and installed dependencies using Yarn. When npm v5 came out, I decided to use npm for the project. I then installed some new dependencies with npm, which deleted all of my installed node_modules (it did not remove them from the package.json file though).

So I thought, "well they're in the package.json file as dependencies and devDependencies, I'll just run npm install to install them all again", but that is not working. It won't install them. Instead I have to see which packages aren't installed and manually add them with npm again.

I have no npm-debug.log file

supporting information:

  • npm -v prints:
    v5.0.3
  • node -v prints:
    v8.1.0
  • npm config get registry prints:
    https://registry.npmjs.org/
  • Windows, OS X/macOS, or Linux?:
    OS X
  • Network issues:
    • Geographic location where npm was run:
      Australia
    • I use a proxy to connect to the npm registry.
    • I use a proxy to connect to the web.
    • I use a proxy when downloading Git repos.
    • I access the npm registry via a VPN
    • I don't use a proxy, but have limited or unreliable internet access.
  • Container:
    • I develop using Vagrant on Windows.
    • I develop using Vagrant on OS X or Linux.
    • I develop / deploy using Docker.
    • I deploy to a PaaS (Triton, Heroku).
@yubaoquan

This comment has been minimized.

Copy link

yubaoquan commented Jun 18, 2017

Seems I met the same problem. I installed a npm module that I wrote.

This module I have tested many times and I can be sure I have declared all dependencies in the package.json.

Npm installed it and did not throw any exceptions or warnings.

But when I run it, a exception was thrown saying a module cannot be found.

@KenanY KenanY added the support label Jun 18, 2017

@mlaffargue

This comment has been minimized.

Copy link

mlaffargue commented Jun 20, 2017

Node v8.1.2
NPM v5.0.3

Same here I took angular-seed project, ran npm install. Everything ok.

I added 4 "dependencies" (jquery, ngx-resource, primeng ...), ran npm install.
But they're not added to node_modules.

I deleted node_modules, ran npm install again, yet my new dependencies aren't installed (the others are).

If I do npm install jquery --save, the package.json isn't modified yet the dependency is present in node_modules folder.

Cleaning the folder and doing npm install again won't install jquery though.

It feels like the first package.json is kept in cache somewhere (I tried a cache clean)
npm list just show me the dependencies aren't met

...
+-- merge-stream@1.0.1
+-- minimatch@3.0.4
+-- UNMET DEPENDENCY ngx-resource@^3.0.5
+-- open@0.0.5
+-- UNMET DEPENDENCY primeng@^4.1.0-rc.1
+-- protractor@4.0.14
...
@sidhuko

This comment has been minimized.

Copy link

sidhuko commented Jun 21, 2017

Have you tried deleting the node_modules/ and package.lock.json and reinstalling?

Came across a similar issue when I was not using npm install [dependency] but adding them directly to package.json.

@mlaffargue

This comment has been minimized.

Copy link

mlaffargue commented Jun 21, 2017

@sidhuko Removing package-lock.json before npm i did the trick.

@jwarkentin

This comment has been minimized.

Copy link

jwarkentin commented Jun 23, 2017

This is a pretty frustrating issue. I'm not sure how it ended up in this state in the first place but I spent way too much time trying to figure out why it wouldn't install my package dependencies. Just removing package-lock.json and doing npm i wasn't enough for me. I had to completely delete the node_modules directory in addition to package-lock.json and then do npm i to get it to work. There are no intuitive error messages and I could swear package-lock.json didn't exist before my last clean npm i.

Is the existence of package-lock.json going to break things when users try to update my module if I add new dependencies? I don't get what it's doing.

@jwarkentin

This comment has been minimized.

Copy link

jwarkentin commented Jun 23, 2017

I realized what I did to get things in this state. I had updated Node.js earlier and didn't realize there was a breaking change with npm. Then on this particular project I was initially just trying to do some updates with npm-check. After that I deleted my node_modules directory and did a fresh npm install not realizing it had generated a package-lock.json which ended up breaking everything.

It seems to me that with a breaking change like this, npm should throw a fatal error if you try to use it when a node_modules directory already exists and there is no package-lock.json. It should tell users they need to delete node_modules and re-install first. It's better to be noisy and clear about this sort of thing than leave users scratching their head for hours with all sorts of unintuitive errors, trying to figure out why everything is broken and their dependencies won't install despite doing a fresh npm install.

@sidhuko

This comment has been minimized.

Copy link

sidhuko commented Jun 23, 2017

I'll agree it's awkward but you certainly take notice of the changes in v5 which is important. You'll need to upgrade with a commit usually so the lockfile is under SCM but once it is there in full then you shouldn't have problems.I'd recommend setting the engines property within package.json to version 5 in the same commit to avoid users adding dependencies which are not on the lockfile.

Alternatively, include an .npmrc with package-lock=false in your folder and it disables this functionality.

@jwarkentin

This comment has been minimized.

Copy link

jwarkentin commented Jun 23, 2017

The functionality isn't bad. It's just not obvious what the upgrade process is. So far I've upgraded 3 of my code bases and in each case it broke until I deleted node_modules and did a fresh npm install with no lock file to start with. Once it gets the initial lock file in place, things seem to be smooth so far moving forward but initially it just doesn't play nicely doing anything with npm 5 against a pre-5 node_modules directory. A simple warning to the user to delete node_modules before proceeding with creating a lock file would go a long way.

@npm-robot

This comment has been minimized.

Copy link

npm-robot commented Jul 10, 2017

We're closing this support issue as it has gone three days without activity. The npm CLI team itself does not provide support via this issue tracker, but we are happy when users help each other here. In our experience once a support issue goes dormant it's unlikely to get further activity. If you're still having problems, you may be better served by joining package.community and asking your question there.

For more information about our new issue aging policies and why we've instituted them please see our blog post.

@npm-robot npm-robot closed this Jul 10, 2017

@ohpyupi

This comment has been minimized.

Copy link

ohpyupi commented Oct 10, 2017

@jwarkentin Thanks man. I have been spending more than four hours to solve this issue. I thought the package that I created got broken for some reasons. However, it was totally from npm5 issue with package-lock.json stuff. I deleted package-lock.json and node_modules entirely and did npm install. It worked just fine. Thanks.

@amiiit

This comment has been minimized.

Copy link

amiiit commented Nov 6, 2017

I fell into this trap as well, eventually to find out I had the NODE_ENV set to production in my current shell session. Closing my shell session and starting a new one did the trick.

@juandiego26

This comment has been minimized.

Copy link

juandiego26 commented Nov 17, 2017

@amiiit Thanks man. I also had the NODE_ENV set to production and for this reason it did not work for me to delete the package-lock.json file, and node_modules folder with npm install command. It worked just fine. Thanks

@xemasiv

This comment has been minimized.

Copy link

xemasiv commented Dec 14, 2017

Almost 2018, removing package-lock still does the trick 👍

@jcdarwin

This comment has been minimized.

Copy link

jcdarwin commented Dec 26, 2017

For others looking here, I had the same problem where npm install finished fine, creating a package-lock.json, but not creating a node_modules folder -- in my case the problem was getting the format of the name wrong in the package.json as I had included a space -- I found this through my linter error:

String does not match the pattern of "^(?:@[a-z0-9-~][a-z0-9-._~]*/)?[a-z0-9-~][a-z0-9-._~]*$".
@gnulnx

This comment has been minimized.

Copy link

gnulnx commented Dec 28, 2017

Removing package-lock.json does not work for me.

npm -v
5.6.0

First I removed old node_modules directory and lock file

rm -rf node_modules package-lock.json

package.json looks like:

{
    "name": "tcart",
    "version": "1.7",
    "dependencies": {
        "lodash": "^4.17.4"
    }
}

Then issued npm command with following output

npm install
npm WARN Invalid version: "1.7"
npm WARN tcart No description
npm WARN tcart No repository field.
npm WARN tcart No README data
npm WARN tcart No license field.

up to date in 0.136s

Look for node_modules directory

ls node_modules
ls: cannot access 'node_modules': No such file or directory
@gnulnx

This comment has been minimized.

Copy link

gnulnx commented Dec 28, 2017

Update that works...

So I manually created the package.json file before. But if I do

npm init

Then an

npm install lodash --save

I get a package.json like:

{
  "name": "tcart",
  "version": "1.0.0",
  "description": "A ecommerce package",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/gnulnx/tcart.git"
  },
  "author": "John Furr",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/gnulnx/tcart/issues"
  },
  "homepage": "https://github.com/gnulnx/tcart#readme",
  "dependencies": {
    "lodash": "^4.17.4"
  }
}

Now if I remove node_modules and lock file

rm -rf node_modules package-lock.json

And run:

npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
added 1 package in 1.614s
ls node_modules/
lodash

So it seems to work if you use npm init to generate the package.json file.

@maxkonyukh

This comment has been minimized.

Copy link

maxkonyukh commented Jan 2, 2018

@jcdarwin Thank you mate, this worked for me as well :)

@rodikno

This comment has been minimized.

Copy link

rodikno commented Jan 9, 2018

It hadn't worked for me and npm list exposed an error that Version of the project in the package.json was set incorrectly (I had it 0.9), I've changed a version to 1.0.0 and the next npm install worked fine for me installing all packages from dependencies list. Maybe this could help for someone.

@pgqueme

This comment has been minimized.

Copy link

pgqueme commented Feb 25, 2018

My package.json had an error with the name (invalid characters). I fixed the name, deleted package-lock.json and node_modules and got it working again.

@AdiBev

This comment has been minimized.

Copy link

AdiBev commented Apr 9, 2018

Turned off the malwarebytes and now it's working fine.

@annelorraineuy

This comment has been minimized.

Copy link

annelorraineuy commented Apr 10, 2018

Ugh. Wasted too much time on this, simply deleting package-lock.json solved the problem for me too.

node 6.11.0
npm 5.4.2

canesqui added a commit to canesqui/product-compare-react that referenced this issue Apr 17, 2018

@Feynt

This comment has been minimized.

Copy link

Feynt commented May 18, 2018

My problem was my name had capital letters in it. Running npm init explained that issue. Changing name to all lower case, no spaces, npm install worked.

@Drag13

This comment has been minimized.

Copy link

Drag13 commented Jun 6, 2018

Ok, guys but why does it fails silently? Isn't silent fail a bug?

@BlitZz96

This comment has been minimized.

Copy link

BlitZz96 commented Jun 8, 2018

In my case this was happening because my forked git package was missing the dist folder from the original package,

@vasudev-hv

This comment has been minimized.

Copy link

vasudev-hv commented Jul 2, 2018

I had added NODE_ENV=production in my environment variables, hence wasn't installing any devDependencies into node_modules. Removed it and is working fine now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.