Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Cannot run npm install on a newly-cloned repository #13123

Closed
schmod opened this issue Oct 19, 2015 · 13 comments
Closed

Cannot run npm install on a newly-cloned repository #13123

schmod opened this issue Oct 19, 2015 · 13 comments

Comments

@schmod
Copy link
Contributor

schmod commented Oct 19, 2015

Running npm install on a freshly-cloned repository fails, and leaves no node_modules folder intact:

> angularjs@ preinstall /home/schmod/source/angular.js
> node scripts/npm/check-node-modules.js --purge

:-( npm dependencies are stale or in an unknown state!
    Purging 'node_modules'...

> angularjs@ postinstall /home/schmod/source/angular.js
> node scripts/npm/copy-npm-shrinkwrap.js

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Failed to copy `npm-shrinkwrap.json` to `node_modules/npm-shrinkwrap.cached.json`:
{ [Error: ENOENT: no such file or directory, open 'node_modules/npm-shrinkwrap.cached.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'node_modules/npm-shrinkwrap.cached.json' }
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

NPM v3.3.8; Node 4.2.1; Ubuntu 15.04

@schmod
Copy link
Contributor Author

schmod commented Oct 19, 2015

It looks like the changes introduced in #12792 / d3de006 will delete the user's node_modules folder when the preinstall script runs if a NPM Shrinkwrap cache file is not present.

I'm assuming that NPM v3.x doesn't add this file before the preinstall scripts are run, which is causing the preinstall script to wipe the node_modules folder that npm install just created.

I'm not sure what the original intent was here, so I can't recommend a fix.

@gkalpak
Copy link
Member

gkalpak commented Oct 26, 2015

I don't see how the changes on #12792 could cause this issue.
The node_modules/ directory is purged before npm install, then npm install runs and creates the node_modules/ directory (installing all necessary modules) and finally the (already existing) npm-shrinkwrap.json file is copied over to node_modules/npm-shrinkwrap.cached.json (which is created then; it doesn't exist already).

The only thing that would make sense, would be if somehow the underlying file created with var ws = fs.createWriteStream(dstPath); (where dstPath is node_modules/npm-shrinkwrap.cached.json) isn't created in time for getting written to (with rs.pipe(ws);.
But this shouldn't be the case, since this is supposed to be taken care of (for quire some time now) in Node.js' fs module.

I am clueless here :( @schmod, can you reproduce it consistently ?

I have only tried on npm v2.x, but I would be surprized if it tuned out to be npm-specific.

@schmod
Copy link
Contributor Author

schmod commented Oct 27, 2015

I just did a fresh clone of the repo on another computer with NPM 3.3.9, and duplicated the issue.

It appears that this is NPM-specific, as NPM's docs only seem to promise that a package's preinstall script will be executed before that same package's install script. It specifically does not promise that the script will run before npm downloads and installs the package's dependencies.

This may be the same issue as npm/npm#9916, although I suspect that very few packages are depending on the NPM lifecycle functioning this way.

tl;dr; Angular's preinstall script appears to depend on an undocumented behavior in NPM that has changed in version 3.x.

@gkalpak
Copy link
Member

gkalpak commented Oct 28, 2015

I confirm that it doesn't work with npm v3.3.9. It seems that the preinstall scripts are run after the dependencies have been installed. I suggest we wait and see what is the response to npm/npm#9916.

@IgorMinar, any insight on this ? This should also affect ng2 (but I haven't tried it).

@schmod
Copy link
Contributor Author

schmod commented Oct 29, 2015

It looks like Node 5.0.0 will be shipping soon, and will be bundled with NPM 3.6.6.

nodejs/node#3466

@gkalpak
Copy link
Member

gkalpak commented Nov 1, 2015

This happens indeed with ng2 as well (node v4.2.1, npm v3.3.9).
Node v5.0.0 has been released with npm v3.3.6, so this should also affect users of both ng1 and ng2 on node v5 :(

@huguangju
Copy link

Whatever version, i didn't download npm package success :(

@gkalpak
Copy link
Member

gkalpak commented Nov 4, 2015

@huguangju, this issue specifically tracks issues with npm v3.x.
Your sounds like a different issue, so if you think this is somehow related to AngularJS (and not for example to node or npm), please open a new issue, providing relevant info (e.g. platform, node/npm version, error messages/faulty behaviour, steps to reproduce etc).

@wbrycki
Copy link

wbrycki commented Mar 25, 2016

Is there a workaround to this issue?
Duplicated on npm 3.6.0
edit: works with node 4.4.1 LTS installed

@gkalpak
Copy link
Member

gkalpak commented Mar 25, 2016

@wbrycki, you could try commenting out the preinstall script hook in package.json:

  "scripts": {
    //"preinstall": "node scripts/npm/check-node-modules.js --purge",
    ...

That's causing one problem for sure. I'm not sure if there are other problems (e.g. dependencies incompatibility issues), but you can give it a shot.

@umerthow
Copy link

just restart you computer and try again to intalling npm by cmd

@Narretz
Copy link
Contributor

Narretz commented Feb 13, 2017

We've since switched to node 6 and npm 3, so this should work now

@Narretz Narretz closed this as completed Feb 13, 2017
@mgol
Copy link
Member

mgol commented Feb 13, 2017

To be precise, we're now on Node 6 and Yarn, not npm 3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants