Thursday, December 28, 2017

Installing SKPM (Sketch Plugin Manager) via npm

Leave a Comment

I've been attempting to install a npm package, which has been throwing a bunch of errors which I'm not too familiar with. Keep in mind that these errors are after executing sudo npm install -g skpm:

gyp ERR! configure error  gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/skpm/node_modules/keytar/build' gyp ERR! System Darwin 17.3.0 gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /usr/local/lib/node_modules/skpm/node_modules/keytar gyp ERR! node -v v8.9.1 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok  npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! keytar@4.1.0 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR!  npm ERR! Failed at the keytar@4.1.0 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.  npm ERR! A complete log of this run can be found in: npm ERR!     /Users/USERNAME/.npm/_logs/2017-12-19T01_53_44_910Z-debug.log 

Originally I'd thought that I needed to install keytar to make this work, but after installing I still had the same errors.

3 Answers

Answers 1

Avoid use sudo npm -g install During gyp compilation you will have such problems again and again. Fixing permissions is the solution.

Quote from npm docs:

You can fix this problem using one of three options:

  1. Change the permission to npm's default directory.
  2. Change npm's default directory to another directory.
  3. Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.

Option 1: Change the permission to npm's default directory

Find the path to npm's directory: npm config get prefix For many systems, this will be /usr/local.

WARNING: If the displayed path is just /usr, switch to Option 2 or you will mess up your permissions.

Change the owner of npm's directories to the name of the current user (your username!):

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).

Option 2: Change npm's default directory to another directory

There are times when you do not want to change ownership of the default directory that npm uses (i.e. /usr) as this could cause some problems, for example if you are sharing the system with other users.

Instead, you can configure npm to use a different directory altogether. In our case, this will be a hidden directory in our home folder.

Make a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

Open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

Back on the command line, update your system variables:

source ~/.profile

Test: Download a package globally without using sudo.

npm install -g jshint

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global

Option 3: Use a package manager that takes care of this for you.

If you're doing a fresh install of Node on Mac OS, you can avoid this problem altogether by using the Homebrew package manager. Homebrew sets things up out of the box with the correct permissions.

brew install node

Answers 2

usually EACCES: permission denied occurs trying to install a package globally (with -g) without providing permissions. Supposing that you are on os with sudo, try call

sudo npm install -g skpm 

or, if you don't want it global

npm install skpm 

Answers 3

I found the issue as to why skpm was not installing.

Make sure you install x-code + command line tools access

This fixed the issue and SKPM installed.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment