npm install fails w/ ENOENT: no such file or directory


(Scott D.) #1

So I’ve been through many, many reports of this bug, but it seems there is a core issue here that is related to dependencies that are included via local includes in the package.json, e.g. “my-module”: “file:…/my-module”

My environment is as follows:
Node - 8.12.0
npm - 6.4.1
OS: Ubuntu 16.04 LTS

At one point, removing node_modules and package-lock.json was working.

As I added more file:…/my-module type dependencies, just removing node_modules and package-lock.json stopped working, what did work was running “npm install” multiple times. It would fail with the above error, then running it again would work. As I added more local dependencies, I had to run “npm install” 3 times.

At this point it has stopped working completely. There are two ways I can get this to work.

If I downgrade npm to 3.10.10 I can remove node_modules, then “npm install” works. The problem is that I have another module that will not build properly w/ npm 3.10.10, but it works fine w/ npm 6.4.1

The other way I can get this to work is to change into my main package folder, then run npm install, manually, for each of the modules included in my package.json file. e.g.

cd my_main_node_server_package
npm install …/my-module1
npm install …/my-module2
npm install …/my-module3

After I do the above, I can cd my_main_node_server_package then:
rm -rf node_modules
rm package-lock.json
npm install

The above works every time.

The thing I noticed is that w/ 3.10.10 copies all of the modules needed to my my_main_node_server_package/node_modules directory, for example, if my-module-1 had aws-sdk in it’s package.json, then aws-sdk gets copied into my_main_node_server_package/node_modules/aws-sdk.

If I use 6.4.1 it copies aws-sdk to my-module-1/node_modules/aws-sdk, then it symlinks my-module-1 into my_main_node_server_package/node_modules/my-module-1.

When using 6.4.1 I cannot get npm install to work with a clean tree. I must either use npm@3.10.10 or I must change into the directory where the main package lives, then type npm install <each_dependent_package>.

Removing package-lock.json does not help.

I’ve seen quite a few reports of this issue, with quite a few workaround, but no fixes. I’d be happy to try something new, pre-release, do some additional testing, provide logs, or whatever is needed to resolve this once and for all. I’m sure you npm devs are tired of hearing about this one, and I’m happy to do whatever I can to help get this resolved. Just to recap:

  1. I believe this is directly related to using local requirements in package.json .e.g. “foo”: “file:…/foo”
  2. The problem does not exhibit itself when using npm@3.10.10 (although there are other issues with other projects I have on the npm@3.10.10 release).
  3. Running “npm install” multiple times throws different errors, in some cases (pointing to a race condition)

If anoyone has a fix, or a better workaround, or needs to ask questions, I am all ears :)


(Scott D.) #2

So here’s how I’m working around this, I wrote the following script (I have modules w/ index.js as the entrypoint and server processes that include modules have server.js as the entry point)\

I run the following in my mono-repo directory that has all of my modules and server processes. After I run the following, npm install in my server directories works and package-lock.json works w/ npm@6.4.1

#!/bin/sh
CWD=pwd

Remove any old node_modules directorys

find . -maxdepth 2 -type d -print | grep node_modules | xargs rm -rf

Run npm install in each of the module directories

for i in find . -maxdepth 2 -name index.js -print
do
MPATH=${i%/*}
echo $MPATH
cd $CWD/$MPATH
/usr/local/bin/npm install
done
cd $CWD


(system) #3

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.