/ node

NPM on Windows - Dealing with long paths

You might have been unfortunate enough to learn that Windows has a 256-character limit on file paths. Then you probably try to put your solutions in a location to make your path as short as possible, like c:\code.

And most of the time this is enough, but when you are using NPM you will soon run in to trouble. This because how NPM handle and stores dependencies. The dependencies for your app, that you specified in the package.json are usually stored in the folder node_modules.

That is all fine, but the then those dependencies may have dependencies of their own, that is stored in their own node_modules folder. This continues in a recursive pattern and pretty soon you end up with a way to long path.

Then Visual Studio may start to complain and you may also have problem deleting the folders. To solve the deleting problem install the node module rimraf:

>npm install -g rimraf

and delete the node_modules folder easily with:

>rimraf node_modules

Ok, but if you are like me that is not enough, we still want to use NPM right! Great news in the next version of NPM (3.x), there will be a solution to the dependency hell.

Your dependencies will now be installed maximally flat. Insofar as is possible, all of your dependencies, and their dependencies, and THEIR dependencies will be installed in your project's node_modules folder with no nesting. You'll only see modules nested underneath one another when two (or more) modules have conflicting dependencies.

Before you install NPM (3.x) and use it in production, be warned that this is still beta software, with potentially a bunch of breaking changes and unknown bugs.

Ok, if you have decided that you want to get your hands dirty and play with it, there is a node package for easy installation called npm-windows-upgrade.

First, you need to ensure that you can execute scripts on your system by running the following command from an elevated command prompt:

>Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

Then, to install the package, run the command:

>npm install -g npm-windows-upgrade

Finally, run the package and select the version you want to install

>npm-windows-upgrade
NPM on Windows - Dealing with long paths
Share this