添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I want to work on a project of mine. I had to factory restart my computer and needed to reinstall everything. I thought I did it and I went to run ionic serve to see my project and start working on it, the console says: zsh: command not found: ionic .

Not sure if this is necessary but the more info I can give I assume the better…

I am using a MacBook Air, running Monterey Version 12.7

node -v
v18.18.0
npm -v
9.8.1
git -v
git version 2.37.1 (Apple Git-137.1)

When I try to run:
npm install -g @ionic/cli

it gives me this:

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/@ionic
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@ionic'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@ionic'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/@ionic'
npm ERR! }
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.
npm ERR! A complete log of this run can be found in: /Users/zdisanto/.npm/_logs/2023-10-02T20_30_06_098Z-debug-0.log

What is going on and how do I fix this?

that’s because, maybe, you used “sudo” command.

Anyway, to fix this type
sudo chmod -R 777 /usr/local/lib/node_modules/

after that try again

Hello

I try my best not to use sudo at all. But now that you mention it I did try to look up this answer on a different forum and they told me to do this:

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Before writing this above, I was still getting the error and decided to ask on here.

Will the code you provided:
sudo chmod -R 777 /usr/local/lib/node_modules/

undo what I typed/just work? Or will it add more errors?

Thank you for your time.

Does this work for you?
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Or you can install the CLI using sudo, but this is absolutely not recommended:
sudo npm install -g @ionic/cli