Situation
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 Questions
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.
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...
General Problem
My Current Hack
Other Unpalatable Workarounds
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.
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.
The problem with deeply nested folders on Windows has been mostly solved starting with npm version 3.x
.
According to npm:
.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.
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.
The problem went away.
You can get the latest npm builds from here : npm releases
Windows 8.1 and 10 have an option to increase the Win32 path limit:
gpedit.msc
and hit Enter)Local Computer Policy\Computer Configuration\Administrative Templates\System\Filesystem
This is a work around solution.
There are some node modules that flattens your dependencies for you.
Links are here:
What these modules are doing can be done manually as well. This is the only real solution exists as of now, i.e to have all your modules at a single level, requiring each other, instead of all having private copies of their dependencies nested deeply.
Allan -
From the github issue you linked,
npm will add dedupe-at-install-time by default. This is significantly more feasible than Node's module system changing, but it is still not exactly trivial, and involves a lot of reworking of some long-entrenched patterns.
This is (finally) currently in the works at npm, going by the name multi-stage-install
, and is targeted for npm@3
. npm
development lead Forrest Norvell is going to spend some time running on Windows in the new year, so please do create windows-related issues on the npm
issue tracker < https://github.com/npm/npm/issues >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With