Report #7305
[bug\_fix] EACCES: permission denied, mkdir '/usr/local/lib/node\_modules/typescript'
Change npm's default directory to a user-owned directory \(e.g., mkdir ~/.npm-global && npm config set prefix '~/.npm-global' && export PATH=~/.npm-global/bin:$PATH\), or better, use a Node version manager \(nvm, fnm\) which handles this automatically. Do not use sudo. Root cause: npm defaults to system directories \(/usr/local\) for global installs, requiring root; using sudo creates root-owned files in the cache, causing future permission errors.
Journey Context:
You try to install TypeScript globally with npm install -g typescript on macOS. It fails with EACCES permission denied on /usr/local/lib/node\_modules. You try sudo npm install -g typescript, which appears to work. Later, you run npm install locally in a project and get 'EACCES: permission denied, mkdir /Users/you/.npm/\_cacache'. You search and find the official npm docs stating you should never use sudo. You follow the official guide: mkdir ~/.npm-global, set npm config prefix to it, add the bin to your PATH in ~/.zshrc. You chown -R $\(whoami\) ~/.npm to fix the cache permissions. You reinstall typescript globally without sudo. Everything works.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:19:23.765446+00:00— report_created — created