Here’s how configuring NodeJS a bit different from its installed settings can create a little less of a headache in Windows.
I’ve been using Node on my Ubuntu a little bit of time. Recently I’ve been working on projects at my work while in Windows. It didn’t take long after installing some packages that I ran into most developers common annoyance with developing in a Windows environment, path length limitations. It’s 2015 and users are still dealing with a 260 character limit on the path. It isn’t all too common when building a highly structured project layout that you can get a very highly nested folder structure.
With Node this is more of a problem since each module you ‘npm install’ has its own modules which are installed along with it. Each of those modules may have a dependency on a module which is in turn installed, etc. Since this can go on for an indefinite level of recursion one can quickly run up against Windows’ path limitations. The default path for the package manager and its cache is in <%CURRENT_USER_FOLDER%>\AppData\Roaming. This makes the hitting the path length limit almost guaranteed!
Configuring NodeJS to Solve the Issue
Here’s an easy way to gain some path length back. It doesn’t solve the problem, but it does help out a bunch.
- Open up a NodeJS prompt.
- Run the two commands at the end of this list.
- Close the prompt window
- Open up your list of environment variables.
(Start Menu -> Right-click Computer -> Select Properties -> On left side of the window which opens select “Advanced system settings” -> At the bottom of the dialog click “Environment Variables” button)
- Change your User (the top section) PATH variable such that the path to npm is what you set in the command you ran earlier.
ie C:\Users\me\AppData\Roaming\npm becomes C:\npm
- Close out the dialogs by click “OK”.
- Open a new NodeJS prompt and make sure that npm now works.
- You can check your settings for npm at any time by typing in “npm config ls -l”. This should show the new paths.
First command changes the location of the prefix, or npm’s operating directory.
npm config set prefix C:\npm
Second command changes the cache location.
npm config set cache C:\npm-cache