4

npm 3.x install fails on rename long paths in Windows/Azure when deploying node.js due to long paths:

npm ERR! EINVAL: invalid argument, rename 'D:\home\site\wwwroot\node_modules\azure_util\node_modules\pkgcloud\node_modules\gcloud\node_modules\gapitoken\node_modules\jws\node_modules\base64url\node_modules\meow\node_modules\indent-string\node_modules\repeating\node_modules\is-finite\node_modules\number-is-nan' -> 'D:\home\site\wwwroot\node_modules\number-is-nan'

Is there away to overcome it or prevent npm from renaming?

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
  • If you can, upgrade to the latest nodejs, the dependencies are flattened so you don't have an endless tree of `node_modules` folder – Shanoor Feb 15 '16 at 15:28
  • @ShanShan I did upgrade that is the problem the npm 3.x is trying to rename the folder inorder to deduplicate but if fails, on the rename... – Guy Korland Feb 15 '16 at 15:32
  • My bad, I read *nodejs* 3.x (wich doesn't even exist). – Shanoor Feb 15 '16 at 15:38
  • What's the package with which you are seeing this? `azure_util` doesn't seem to exist in npm. Also, do you get the same behavior when running npm manually using [Kudu Console](https://github.com/projectkudu/kudu/wiki/Kudu-console)? – David Ebbo Feb 15 '16 at 17:01
  • @DavidEbbo azure_util is our internal package, but the same issue happens even if we strip it out. As long as the path to the 'number-is-nan' is longer than 260 we fail. I just found an issue in Kudo https://github.com/projectkudu/kudu/issues/1696 :) – Guy Korland Feb 15 '16 at 17:03

2 Answers2

4

We found a solution. It seems like npm 3.x is getting to this situation when it needs to rename a long path only when you upgrade from older npm.

Meaning, since we already had this deployment running with an older npm, when we upgraded to npm 3.6.0 it tried to flatten the existing deployment and crashed.

The solution was just to remove the node_modules and redeploy.

Guy Korland
  • 9,139
  • 14
  • 59
  • 106
  • I'm getting a similar issue, but I already have my bitbucket repo ignoring the node_modules folder altogether. Still getting the error on the Azure deployment task – ganders Dec 09 '16 at 15:48
0

According your info, your custom module azure_util is build in npm <3.x version, which has nested the node_modules folders.

You can try the following steps before deploying your node.js application to Azure Web Apps:

  1. upgrade your local npm version up to 3.x version.
  2. run command npm dedupe in your application directory, which will flatten the tree. You can find the description in npm change log

After these operations, your application's node.js deps should flat list in node_modules folder. And it should prevent the npm rename.

If you still occur the issue on your local env, you can try to rebuild your custom dependency in npm 3.x version, to make the directory tree flat in advance.

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • I'm not sure I follow your solution. azure_util is just a module with dependencies. We're deploying to Azure using the "continuous integration" right from our git. – Guy Korland Feb 16 '16 at 19:56
  • Your issue is that the `azure_util` module contains some other modules which makes the path too long, so when you leverage "continuous" deploy to Azure, it OS cannot handle the file. So have you flat the `azure_util` module without nested `node_modules` folder inside. Then I think will fix this issue. – Gary Liu Feb 17 '16 at 01:28
  • How can I flatten external modules I depend on? – Guy Korland Feb 17 '16 at 05:26
  • is the `azure_util` has `project.json` file and `node_modules` folder? you can in the `azure_util` run `npm dedupe`, or remove the `node_modules` folder and run `npm install`. Keep npm version is up to 3.x – Gary Liu Feb 17 '16 at 06:22