pnpm 的安裝源太多了,感覺系統變量都有引入順序。
今天踩坑記錄:
pnpm ,如果最初用npm 裝的,可以用npm 升級;
如果最初用brew 裝的,得用brew 升級;
如果最初是用corepack 裝的得用corepack 升級;
由于項目需要,我今天直接:npm install -g pnpm@10.12.4
然后,就 Error: EACCES: permission denied, access ‘/usr/local/lib/node_modules’
npm install -g pnpm@10.12.4
npm error code EACCES
npm error syscall mkdir
npm error path /usr/local/lib/node_modules/lib/node_modules/pnpm
npm error errno -13
npm error Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/lib/node_modules/pnpm'
npm error at async mkdir (node:internal/fs/promises:859:10)
npm error at async /usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:638:20
npm error at async Promise.allSettled (index 0)
npm error at async [reifyPackages] (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:336:11)
npm error at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:141:5)
npm error at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:149:5)
npm error at async Npm.exec (/usr/local/lib/node_modules/npm/lib/npm.js:208:9)
npm error at async module.exports (/usr/local/lib/node_modules/npm/lib/cli/entry.js:67:5) {
npm error errno: -13,
npm error code: 'EACCES',
npm error syscall: 'mkdir',
npm error path: '/usr/local/lib/node_modules/lib/node_modules/pnpm'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It is likely you do not have the permissions to access this file as the current user
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
改變文件的權限:
- First check who owns the directory
ls -la /usr/local/lib/node_modules
它拒絕訪問,因為節點模塊文件夾歸root所有。
因此,需要將root更改為您的用戶,但首先運行下面的命令來檢查當前用戶
在控制臺輸入:id -un
OR whoami
然后去改變owner
sudo chown -R $USER /usr/local/lib/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/
再檢查文件所屬權:
然后我再執行 sudo npm install -global pnpm
呃,這。
腦子里忽然閃過一丟靈光,感覺是系統變量引入順序的問題。我看公司的這臺電腦里是裝了brew
和 corepack
的
我就試了試:brew
結果和 npm 升級 pnpm 一樣。
最后我試了試corepack
corepack enable pnpm
corepack use pnpm@latest-10
然后就好了
pnpm -v
10.12.4
然后我開始裝包:pnpm install
pnpm install gives no such file or directory, mkdir '/home/vsts error.
?ENOENT? ENOENT: no such file or directory, mkdir '/home/vsts'pnpm: ENOENT: no such file or directory, mkdir '/home/vsts'at async Object.mkdir (node:internal/fs/promises:859:10)at async createNewStoreController (/Users/edy/.cache/node/corepack/v1/pnpm/10.12.4/dist/pnpm.cjs:101790:7)
通過搜索找到答案:手動設置路徑:pnpm config set store-dir /path/to/pnpm/store/v3
.
Make sure that the path actually exists.
參考資料:https://github.com/pnpm/pnpm/issues/4936
設置路徑后,再次裝包
pnpm no such file or directory, mkdir ‘/path’
?ENOENT? ENOENT: no such file or directory, mkdir '/path'pnpm: ENOENT: no such file or directory, mkdir '/path'at async Object.mkdir (node:internal/fs/promises:859:10)at async createNewStoreController (/Users/edy/.cache/node/corepack/v1/pnpm/10.12.4/dist/pnpm.cjs:101790:7)at async installDeps (/Users/edy/.cache/node/corepack/v1/pnpm/10.12.4/dist/pnpm.cjs:159048:21)
找到答案:pnpm config set store-dir ~/pnpm
參考資料:https://blog.csdn.net/qq_37655530/article/details/129228561
哎,終于搞好了。
參考資料:
https://stackoverflow.com/questions/48910876/error-eacces-permission-denied-access-usr-local-lib-node-modules
https://github.com/pnpm/pnpm/issues/4936
https://blog.csdn.net/qq_37655530/article/details/129228561