npm failing with space in file path

I had updated some node stuff on my system one day (macOS 10.13.6). Later, when I went to work on a Laravel project, I discovered somewhere along the line I had broken something. Laravel would not run.

I thought perhaps my packages for this project were messed up so I tried reinstall them via npm install , but that was erroring. After a lot of frustration and research, I narrowed it down to the node-gyp package causing the problems. It appears it doesn’t support spaces in paths (that’s what this conversation was saying at least). The space in question here is the space in my main macOS user home directory path. I have my home directory on a separate drive from my system. That drive is named “User Drive”. node-gyp was trying to write some temp files inside my home dir and the error message was saying something along the lines of can’t find “Drive/myusername/yadayada”. Well, that’s because it’s not “Drive/myusername/yadayada“, it’s “User Drive/myusername/yadayada“!  I find it very odd that a mature software in 2019 would have such an issue ????

The solution

On the main node-gyp page, I found that I can set the temp directory to something other than my space-having home path. I just did this:

export npm_config_devdir=/tmp/.gyp

I was then able to run npm install which fixed my laravel project. All was good again.

Author: Joel Mama

I own a Web development company in Portland, OR called Prise Design Group (PDG for short).

Leave a Reply

Your email address will not be published. Required fields are marked *