Too long paths because of nested node dependencies

2020-02-26 12:59发布

I'm using npm to install dependencies. After I have installed those, I want to share my project with someone who is not technical, and doesn't have npm, so I want to ship the node_modules inside the app.

However, because node nests the dependencies, it creates a file that has a very long path (217 characters)

node_modules\express\node_modules\connect\node_modules\multiparty\node_modules\readable-stream\node_modules\string_decoder\build\node_modules\cheerio\node_modules\htmlparser2\node_modules\domhandler\test\cases\04-unescaped_in_script.json

The problem (on windows) is that when the end users tries to copy/paste the folder with too long filenames, he gets the following error:

enter image description here

Is it for example possible to tell npm to install the dependencies in a folder called nm , so that the problem would more likely not appear.

标签: node.js path npm
2条回答
【Aperson】
2楼-- · 2020-02-26 13:35

To circumvent the problem, I would try:

  1. Mapping the path to a virtual drive. If it's a network-shared folder, you can use "Tools->Map Network drive", if not, you can use the "subst" command. More info here: http://www.makeuseof.com/tag/how-to-map-a-local-windows-folder-to-a-drive-letter/

  2. Since the problem is just copying a set of folder, why not try Robocopy? It has support for longer filepaths than the native Windows Explorer.

查看更多
趁早两清
3楼-- · 2020-02-26 13:45

The situation has gone better with upcoming npm 3. Earlier I had to develop close to the root folder of the drive (c:\GH), but npm 3 has a more flat hierarchy. In a very rare circumstances, there might be a really long path name. That would happen if there are version conflicts and npm would have to install a package in a sub-folder instead of the node_modules root.

Shameless plug: I wrote a blog post about the problem & solution

查看更多
登录 后发表回答