npm 3.x 安装在重命名 Windows/Azure 中的长路径时失败

npm 3.x install fails on rename long paths in Windows/Azure

npm 3.x 在部署 node.js 时重命名 Windows/Azure 中的长路径安装失败,原因是长路径:

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'

有没有办法克服它或防止 npm 重命名?

根据您的信息,您的自定义模块 azure_util 是在 npm <3.x 版本中构建的,它嵌套了 node_modules 文件夹。

在将 node.js 应用程序部署到 Azure Web Apps 之前,您可以尝试以下步骤:

  1. 将您的本地 npm 版本升级到 3.x 版本。
  2. 运行命令npm dedupe in your application directory, which will flatten the tree. You can find the description in npm change log

完成这些操作后,您的应用程序的 node.js 部门应该在 node_modules 文件夹中列出。它应该可以防止 npm 重命名。

如果你的本地环境仍然出现这个问题,你可以尝试在npm 3.x版本中重建你的自定义依赖,提前使目录树变平。

我们找到了解决办法。似乎 npm 3.x 遇到这种情况时,只有当您从旧的 npm 升级时才需要重命名长路径。

意思是,因为我们已经有了这个部署 运行 一个旧的 npm,当我们升级到 npm 3.6.0 时它试图扁平化现有的部署并崩溃了。

解决方案只是删除 node_modules 并重新部署。