Cannot install a package from a read-only directory

What I Wanted to Do

Install (copy) a package from a read-only directory into local node_modules.

What Happened Instead

$ npm --loglevel=verbose  i file:/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1
npm info it worked if it ends with ok
npm verb cli [ '/nix/store/dc6vl2h4177jpcws78g7z9pwmqja0110-nodejs-10.16.3/bin/node',
npm verb cli   '/home/pashev/.nix-profile/bin/npm',
npm verb cli   '--loglevel=verbose',
npm verb cli   'i',
npm verb cli   'file:/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1' ]
npm info using npm@6.9.0
npm info using node@v10.16.3
npm verb npm-session 2215c53dfc87e235
npm timing stage:loadCurrentTree Completed in 96ms
npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
npm timing stage:loadIdealTree:loadShrinkwrap Completed in 11ms
npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 56ms
npm timing stage:loadIdealTree Completed in 72ms
npm WARN checkPermissions Missing write access to /nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1
npm timing stage:rollbackFailedOptional Completed in 1ms
npm timing stage:runTopLevelLifecycles Completed in 185ms
npm WARN enoent ENOENT: no such file or directory, open '/home/pashev/work/projects/nix/nix2npm/package.json'
npm verb enoent This is related to npm not being able to find a file.
npm verb enoent 
npm WARN nix2npm No description
npm WARN nix2npm No repository field.
npm WARN nix2npm No README data
npm WARN nix2npm No license field.

npm verb stack Error: EACCES: permission denied, access '/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1'
npm verb cwd /home/pashev/work/projects/nix/nix2npm
npm verb Linux 5.2.0-2-amd64
npm verb argv "/nix/store/dc6vl2h4177jpcws78g7z9pwmqja0110-nodejs-10.16.3/bin/node" "/home/pashev/.nix-profile/bin/npm" "--loglevel=verbose" "i" "file:/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1"
npm verb node v10.16.3
npm verb npm  v6.9.0
npm ERR! path /nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1'
npm ERR!  { [Error: EACCES: permission denied, access '/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm verb exit [ -13, true ]
npm timing npm Completed in 1117ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pashev/.npm/_logs/2019-09-29T11_52_01_494Z-debug.log

Reproduction Steps

$ rm -rf node_modules
$ npm i /some/readonly/package/dir

Platform Info

$ npm --versions
{ npm: '6.9.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.9.2',
  icu: '64.2',
  modules: '64',
  napi: '4',
  nghttp2: '1.39.2',
  node: '10.16.3',
  openssl: '1.1.1d',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.30.1',
  v8: '6.8.275.32-node.54',
  zlib: '1.2.11' }

$ node -p process.platform
linux

I was not able to reproduce this on the first install from a read-only directory, but did get a similar error when I tried installing again, I suspect because the destination node_modules now contained a link to the non-writeable location. My errors referred to the destination folder not the source, so slightly different than yours.

You do not appear to have a package.json in that log which means npm is going to go up the file hierarchy looking for a possible project home folder. That is an extra complication, and I suggest to make more reproducible you add a local package.json (npm init -y).

What are the permissions on that folder?

ls -ald /nix/store/d03k5f0k56r2qnq9wwbkpks7v72hnmj0-nodejs-10.16.3-color-convert-2.0.1

I figured. The package should have dependencies, and npm is trying to create node_modules in the directory of the package. I also tried it with Debian where we have /usr/lib/nodejs/ (read-only).

1 Like