The Node Snap

Created at 2020-01-07 Updated at 2020-06-10 Tag snap package / node

TL;DR

If you installed the NodeJS Snap package, and while trying to install an npm package you recieve this error:

WARNING: cannot create user data directory: cannot create "/nonexistent/snap/node/xxxx": mkdir /nonexistent: permission denied
cannot create user data directory: /nonexistent/snap/node/xxxx: Permission denied

Run this command to fix it:

$ sudo npm config set scripts-prepend-node-path true

The Rest of the Story

I have the NodeJS Snap package installed on a Linux Mint 19.3 PC. I wanted to install the katacoda-cli npm package, but I kept getting this error:

WARNING: cannot create user data directory: cannot create "/nonexistent/snap/node/xxxx": mkdir /nonexistent: permission denied
cannot create user data directory: /nonexistent/snap/node/xxxx: Permission denied

While searching for an anwser, I found that the error is not specific to the katacoda-cli npm package, so this should apply to other packages producing the same error.

I would like to reiterate, that I am using the NodeJS Snap Package. Using the standard deb/apt package to install NodeJS does not produce this error.

So, in order to resolve the NodeJS Snap error, you just need to run the following command:

$ sudo npm config set scripts-prepend-node-path true

After that, I was able to install katacoda-cli npm package:

$ sudo npm install katacoda-cli --global

All credit for this solution goes to the this GitHub issue comment. Thanks a bunch to the poster!

That's all for this post; short and sweet!

End of Line.

Table of Contents

  1. TL;DR
  2. The Rest of the Story
Site by Aaron von Awesome using Hexo & Random