Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue installing netlify-cli with resulting EACCES permission denied error #3870

Closed
maxcell opened this issue Dec 20, 2021 · 31 comments · Fixed by #4076
Closed

Issue installing netlify-cli with resulting EACCES permission denied error #3870

maxcell opened this issue Dec 20, 2021 · 31 comments · Fixed by #4076
Assignees
Labels
type: bug code to address defects in shipped code

Comments

@maxcell
Copy link
Contributor

maxcell commented Dec 20, 2021

Describe the bug

For some reason, when installing the netlify-cli we ran into an EACCES denied error to the autocompletion.json file. It seems to pass through when we use sudo in front of installing but this is even from a fresh install of nvm. And invoking the cli with sudo seems to work fine, but any other way fails.

To Reproduce

Steps to reproduce the behavior:

  1. Run npm install netlify-cli -g
  2. Error outputs

Configuration

This is at the global install level even outside of a given project.

Here is the output of npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli:

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 1.24 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    npm: 8.3.0 - ~/.nvm/versions/node/v16.13.1/bin/npm

Expected behavior

It should properly install without any error output. The CLI should be usable without sudo in front.

CLI Output

Here is the error output we're seeing:

EACCES error

francisagulto@franciss-MBP recipes % npm install -g netlify-cli 
npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated rollup-plugin-inject@3.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated node-pre-gyp@0.13.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm ERR! code 7
npm ERR! path /Users/user_name/.nvm/versions/node/v16.13.1/lib/node_modules/netlify-cli
npm ERR! command failed
npm ERR! command sh -c node ./scripts/postinstall.js
npm ERR! /Users/user_name/.nvm/versions/node/v16.13.1/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
npm ERR!       throw ex;
npm ERR!       ^
npm ERR!
npm ERR! Error: EACCES: permission denied, open '/Users/user_name/Library/Preferences/netlify/autocompletion.json'
npm ERR!     at Object.openSync (node:fs:585:3)
npm ERR!     at writeFileSync (node:fs:2153:35)
npm ERR!     at createAutocompletion (/Users/user_name/.nvm/versions/node/v16.13.1/lib/node_modules/netlify-cli/src/lib/completion/generate-autocompletion.js:33:3)
npm ERR!     at postInstall (/Users/user_name/.nvm/versions/node/v16.13.1/lib/node_modules/netlify-cli/scripts/postinstall.js:36:5)
npm ERR!     at Object. (/Users/user_name/.nvm/versions/node/v16.13.1/lib/node_modules/netlify-cli/scripts/postinstall.js:56:1)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
npm ERR!   errno: -13,
npm ERR!   syscall: 'open',
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/user_name/Library/Preferences/netlify/autocompletion.json'
npm ERR! }

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user_name/.npm/_logs/2021-12-17T22_38_12_208Z-debug-0.log

Additional context

This was on a fresh M1 MacBook installation. This was on a fresh nvm installation as well. The correct path for node and npm seemed to be fine as well.

@maxcell maxcell added the type: bug code to address defects in shipped code label Dec 20, 2021
@lukasholzer
Copy link
Collaborator

@ehmicky any ideas why writing in the same directory as netlify config has issues? I have used the same method as the config to get the file and write it there on startup.

@ehmicky
Copy link
Contributor

ehmicky commented Dec 20, 2021

Not that I can think of. However, I am wondering if this might be related to #3841?

@Fran-A-Dev
Copy link

I tried to install it again into a local project and it did the same error. I tired to use a different version of node which did not work as well.

@Fran-A-Dev
Copy link

Now sudo is not working either when trying to install it.sudo npm install netlify-cli --g

@lukasholzer
Copy link
Collaborator

@Fran-A-Dev hey can you provide more details on the npm install? which operating system and npm version is used?

thx already in advance :)

@Fran-A-Dev
Copy link

Hi Lukas! Thanks so much for looking into this. The npm version I am using is 8.3.0

The OS I am on is macOS Monterey version 12.1

Thank you!

@Fran-A-Dev
Copy link

@lukasholzer I just tried again today after re-installing nvm and still same error. I wonder what could be causing this.

@lukasholzer
Copy link
Collaborator

@Fran-A-Dev, @maxcell

I've created a rc release with a fix. Can you verify if it worked for you?

npm install -g netlify-cli@8.9.7-rc.0

@Fran-A-Dev
Copy link

@lukasholzer , @maxcell

I just ran the command and it works!!!! Yes! JAMstack Joy!! Thank you so much!! I appreciate you!
Screen Shot 2022-01-18 at 10 56 05 AM

@lukasholzer
Copy link
Collaborator

@Fran-A-Dev thank you for verifying release is coming :)

@Fran-A-Dev
Copy link

Super stoked! @lukasholzer I was missing the shared dev server over HTTPS tunnel and the lamba proxy on dev environment it does out of the box.

@Fran-A-Dev
Copy link

Fran-A-Dev commented Jan 18, 2022 via email

@lukasholzer lukasholzer reopened this Jan 19, 2022
@lukasholzer
Copy link
Collaborator

I Reopened the issue and added your comment here

@lukasholzer I tried to run netlify help after successfully installing the netlify cli globally and I got this output:
Screen Shot 2022-01-18 at 2 07 37 PM
Screen Shot 2022-01-18 at 2 07 53 PM

Did I need to run an additional command in terminal after install?

Originally posted by @Fran-A-Dev in #4076 (comment)

@lukasholzer lukasholzer self-assigned this Jan 19, 2022
@Fran-A-Dev
Copy link

Thank you @lukasholzer ! It was strange, when I installed it per your new release it successfully installed, then when trying to run a netlify utility command, it gave the error I sent you. Progress wise though, at least we got it installed. Thanks again for assisting on this!

@lukasholzer
Copy link
Collaborator

can you send me your os information and more details about the environment?
Something like that:
CleanShot 2022-01-19 at 15 41 35@2x

@Fran-A-Dev
Copy link

Sure thing @lukasholzer , can I just run that exact command in the screenshot on my terminal
npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify cli ?

@Fran-A-Dev
Copy link

Here is a screenshot of the system
Screen Shot 2022-01-19 at 9 39 04 AM

@lukasholzer
Copy link
Collaborator

npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify cli

yep exact this command it will download a npm package that analyzes your system:

should print something like that:

 npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify cli
Need to install the following packages:
  envinfo
Ok to proceed? (y) Y

  System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 10.66 GB / 64.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.1/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm

@Fran-A-Dev
Copy link

Awesome, just ran the command, here is the output @lukasholzer :

Screen Shot 2022-01-19 at 11 01 32 AM

@lukasholzer
Copy link
Collaborator

lukasholzer commented Jan 20, 2022

So this looks all good, I see you invoke with npm?

I cannot reproduce it so please help my to troubleshoot this.

Can you verify if this folder exists on your system?
/Users/francisagulto/Library/Preferences/netlify

If yes can you print me the privileges of the folder?

ls -lah /Users/francisagulto/Library/Preferences/netlify

CleanShot 2022-01-20 at 15 58 37

and last but not least can you try writing to this folder with node?

node -e "require('fs').writeFileSync('/Users/francisagulto/Library/Preferences/netlify/test.json', '{}', 'utf-8')"

after that run again:

ls -lah /Users/francisagulto/Library/Preferences/netlify

this would verify if your node.js installation has issues with permissions.

@Fran-A-Dev
Copy link

ahhh @lukasholzer ok let me try that now, One second here.

@Fran-A-Dev
Copy link

@lukasholzer forgive me but what is the correct syntax in shell script to check if this /Users/francisagulto/Library/Preferences/netlify exists?

@Fran-A-Dev
Copy link

@lukasholzer I ran this command, I think this is correct, it outputted that it does exists:
Screen Shot 2022-01-20 at 10 12 30 AM

@Fran-A-Dev
Copy link

@lukasholzer Did the commands and here is all the output it gave:
Screen Shot 2022-01-20 at 10 15 24 AM

@lukasholzer
Copy link
Collaborator

yea thanks @Fran-A-Dev so we can track down it is not an issue of the CLI per se it seems you have installed node.js with a different user probably that is not allowed to write into your Library/Preferences folder.

@ehmicky @erezrokah asking (as netlify is general relying on this folder if we should pick a different one?) 🤔

@Fran-A-Dev
Copy link

@lukasholzer Ok that is good to know. I will stand by and wait for your instructions on how to proceed to fix my permissions.

@erezrokah
Copy link
Contributor

erezrokah commented Jan 21, 2022

We use https://github.com/sindresorhus/env-paths to get the recommended user specific directory:

const pathInHome = path.join(OSBasedPaths.config, ...paths)

I was able to reproduce this issue by running:

  1. On a fresh install (with no prior Library/Preferences/netlify directory) run npm install -g netlify-cli
  2. Run sudo ntl status to make sure the config.json is created (it will be created as root).
  3. Run ntl status and see that it fails with the following error:
You don't have access to this file.

This is basically this issue yeoman/configstore#34 (comment), where if you ran the CLI using sudo once, it can overwrite the permissions.

You can find what Configstore uses here https://github.com/yeoman/configstore/blob/02f07ead1cbbc1c8b49e3c9ba6e7a4896594368d/index.js#L12

Not sure if this was solved by the new version of the library here:
https://github.com/sindresorhus/conf#configfilemode

@Fran-A-Dev a possible workaround is to delete the directory and let the CLI regenerate the files via:

  1. sudo rm -rf /Users/francisagulto/Library/Preferences/netlify/
  2. npm install -g netlify-cli
  3. ntl login

Going forward I believe the fix is to ensure we don't generate config.json under root, but as the current underprivileged user.

@lukasholzer and @Fran-A-Dev please let me know what you think.

@Fran-A-Dev
Copy link

@erezrokah I can try that workaround and see what happens. One second, I can try it momentarily.

@Fran-A-Dev
Copy link

@lukasholzer @erezrokah Perfect! Success! It worked, it logged me into my Netlify dashboard. Thanks so much for the help!
Screen Shot 2022-01-21 at 7 19 25 AM

@WillowMT
Copy link

Hello! I just wanted to share a solution I came up with in the permission error as well. So what I did was headed to the ~/Library/Preferences/netlify folder and opened the "get info" option. Then I manually added my user in the "Sharing and Permission" section, together with read & write beside my user. After that, reload the terminal and all's good to go!

@PierBover
Copy link

I just stumbled upon this problem.

The solution was simply to delete the prefs folder, and install again using npm install netlify-cli -g.

Initially I installed the CLI using sudo sudo npm install netlify-cli -g but then I did the setup to be able to install global packages without sudo. And so the ~/Library/Preferences/netlify folder had been created previously by root and not my user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants