节点 npm windows 文件路径太长无法安装包 [英] Node npm windows file paths are too long to install packages

查看:28
本文介绍了节点 npm windows 文件路径太长无法安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

我想在 Windows 托管的开发环境中使用 gulp 和相关的前端工具链.我在尝试使用像 Browser-Sync 这样的 gulp 插件时碰壁了,因为 node_modules 文件夹图扇出使 windows 文件路径太长而无法复制文件.我想要一种务实的方法来立即在 Windows 上处理这个问题,而不管 Node 社区将来可能会提供或不会提供什么来提高 Windows 上的 npm 可用性.

I want to use gulp and related front-end tool chains in Windows-hosted development environments. I'm hitting a wall trying to use gulp plug-ins like Browser-Sync, because the node_modules folder graph fans out making the windows file paths too long to copy the files. I'd like a pragmatic approach for handling this problem right now on Windows, irrespective of what the Node community may or may not provide to improve npm usability on the Windows in the future.

2 个问题

  1. 是否有适用于 Windows 的 npm 工作流程可以按照预期的方式工作?运行命令并安装文件"(例如,与 OSX 上的 npm、Linux 上的 npm、ruby gems 甚至 nuget 相当)我不想每次使用时都摆弄一堆手动文件编辑、符号链接等Windows 上的 npm.

  1. Is there an npm workflow for Windows that just works the way it was intended? "run the command and the files install" (e.g. comparable to npm on OSX, npm on Linux, ruby gems or even nuget) I don't want to fiddle with a bunch of manual file edits, symlinks, etc. every time I use npm on Windows.

是否有完善的、稳定的 Cygwin 工作流程用于 npm 和节点执行来解决 Windows API 文件路径限制?

Is there a well-documented, stable Cygwin workflow for npm and node execution to workaround the Windows API file path limits?

下面列出的血腥细节...

Gory details listed below...

一般问题

  • 在深度嵌套的 node_modules 层次结构上,从标准 Windows 命令提示符运行 npm install 失败.
  • 根据 Joyent 的 github 存储库线程,这是一个公认的问题对于以 Windows 为中心的环境中的开发人员来说,没有合适的解决方法.(真的吗?)
  • NT 内核支持最多 32,767 个字符的文件路径长度.
  • Windows API 的 MAXPATH 限制为 260 个字符.
  • Windows API 处理所有主要 Windows shell 的文件操作,包括:资源管理器、CMD、Powershell、MYSgit bash 等(真的是 MS?NTFS 出现多久了?)
  • Cygwin 支持长文件路径,但 npm.cmd 由于 crlf 格式而无法开箱即用.我在 npm 上尝试了 DOS2Unix 转换以使其与 Cygwin 一起使用,但似乎还有其他问题.
  • Running npm install from a standard Windows command prompt fails on deeply nested node_modules hierarchies.
  • Per Joyent's github repo thread, this is an acknowledged issue with no palatable workarounds for developers in Windows-centric environments. (Really?)
  • NT Kernel supports file path lengths up to 32,767 characters.
  • Windows API's MAXPATH is limited to 260 characters.
  • Windows API handles file operations for all major Windows shells and whatnot including: Explorer, CMD, Powershell,MYSgit bash, etc. (MS really? How long has NTFS been around?)
  • Cygwin supports long file paths, but npm.cmd doesn't work out-of-box due to crlf formatting. I tried the DOS2Unix transform on npm to get it working with Cygwin, but there seem to be other issues with this.

我目前的黑客

  • 在 C: 的根目录上创建一个n"文件夹作为暂存区,因为这缩短了我的文件夹路径.
  • 在n"文件夹中运行 npm 以安装我需要的任何模块.
  • 启动 Cygwin 并使用 cp 将 node_modules 文件夹复制到目标项目中.
  • 在依赖项发生变化或我需要启动新项目时进行冲洗和重复.

其他令人不快的解决方法

符号链接可用于缩短文件路径,但这些都是笨拙的技巧.随着 npm 生态系统的发展,嵌套的依赖链会变得过长,这种变通方法变得不可用.

Symbolic Links can be used to shorten file paths, but these are kludgy hacks. As the npm ecosystem grows, nested dependency chains will become too long and this workaround become unusable.

将所有依赖项添加到根文件夹的 package.json 文件在我遇到的一个线程中提到.虽然这种方法会扁平化文件夹结构并防止加载重复的模块,但这种解决方法感觉不自然.它还破坏了 npm 的可用性、耐用性和生产力,因为您必须手动或使用一些 hacky 脚本在安装后摆弄文件和文件夹.这种方法也容易受到符号链接方法最终可能遭受的同样命运的影响.

Adding ALL dependences to the root folder's package.json file was mentioned in one thread I came across. Although this approach will flatten the folder structure and prevent loading of duplicate modules, this workaround feels unnatural. It also kills the usability, durability, and productivity of npm, because you have to fiddle with files and folders post-install either manually or with some hacky scripts. The approach is also vulnerable to the same fate that Symbolic Links approach may eventually suffer.

推荐答案

从 npm 版本 3.x 开始,Windows 上深度嵌套文件夹的问题已基本解决.

The problem with deeply nested folders on Windows has been mostly solved starting with npm version 3.x.

根据 npm:

.npm@3 通过将所有可能的东西提升到顶级 node_modules 来使安装最大程度地平坦".这意味着嵌套只发生在冲突中,因此,树永远不会变得很深.因此,不应遇到 Windows 路径长度限制.

.npm@3 makes the install "maximally flat" by hoisting everything it can to the top level node_modules. This means nesting only occurs on conflicts and as such, trees should never get very deep. As such, the windows path length limitation shouldn't be run into.

我刚刚安装了 npm 3.1.0 并在抛出可怕的指定的路径、文件名或两者都太长错误的包上进行了尝试.

I have just installed npm 3.1.0 and tried it out on a package that was throwing the dreaded The specified path, file name, or both are too long error.

问题就解决了.

您可以从这里获取最新的 npm 版本:npm 版本

You can get the latest npm builds from here : npm releases

这篇关于节点 npm windows 文件路径太长无法安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆