Open7

npmのキャッシュフォルダ

豚&紙箱豚&紙箱

ZennとQiitaの記事をGitHubで管理するために、ローカルにNode.jsをインストールしました。
Node.jsはDドライブにインストールしました。しかし、npmのキャッシュディレクトリはCドライブにあると、npxコマンドを実行する時に気づきました。

> npx zenn init
npm error could not determine executable to run
npm error A complete log of this run can be found in: C:\Users\zzxia\AppData\Local\npm-cache\_logs\2025-07-12T03_12_52_975Z-debug-0.log
豚&紙箱豚&紙箱

キャッシュフォルダを確認します。

> npm config get cache
C:\Users\zzxia\AppData\Local\npm-cache
> npm config get --global cache
C:\Users\zzxia\AppData\Local\npm-cache
豚&紙箱豚&紙箱

npm-cacheフォルダをC:\Users\zzxia\AppData\Local\からD:\Program Files\nodejs\に移動し、キャッシュフォルダの設定を更新しました。

> npm config set cache "D:\Program Files\nodejs\npm-cache" --global
>

しかし、その後、キャッシュの検証は通りませんでした。

> npm --global cache verify
npm error code EPERM
npm error syscall open
npm error path D:\Program Files\nodejs\npm-cache\_cacache\index-v5\07\2f\c26409f0f3f5f0a9723c9865acfaf682ce8a5f593e491d912d58f53f9ae7
npm error errno -4048
npm error Error: EPERM: operation not permitted, open 'D:\Program Files\nodejs\npm-cache\_cacache\index-v5\07\2f\c26409f0f3f5f0a9723c9865acfaf682ce8a5f593e491d912d58f53f9ae7'
npm error     at async open (node:internal/fs/promises:639:25)
npm error     at async truncate (node:internal/fs/promises:792:14)
npm error     at async rebuildBucket (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\cacache\lib\verify.js:218:3)
npm error     at async file:///C:/Users/zzxia/AppData/Roaming/npm/node_modules/npm/node_modules/p-map/index.js:121:20 {
npm error   errno: -4048,
npm error   code: 'EPERM',
npm error   syscall: 'open',
npm error   path: 'D:\\Program Files\\nodejs\\npm-cache\\_cacache\\index-v5\\07\\2f\\c26409f0f3f5f0a9723c9865acfaf682ce8a5f593e491d912d58f53f9ae7'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
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.
npm error Log files were not written due to an error writing to the directory: D:\Program Files\nodejs\npm-cache\_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
豚&紙箱豚&紙箱

管理者権限で検証コマンドを実行したら成功しました。

> npm --global cache verify
Cache verified and compressed (D:\Program Files\nodejs\npm-cache\_cacache)
Content verified: 225 (35019027 bytes)
Index entries: 225
Finished in 1.227s
豚&紙箱豚&紙箱

管理者権限じゃないとnpm installもできないようです。

> npm install zenn-cli
npm error code EPERM
npm error syscall mkdir
npm error path D:\Program Files\nodejs\npm-cache\_cacache\tmp
npm error errno EPERM
npm error FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/zenn-cli: EPERM: operation not permitted, mkdir 'D:\Program Files\nodejs\npm-cache\_cacache\tmp'
npm error     at C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm error     at async Response.json (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm error     at async RegistryFetcher.packument (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\lib\registry.js:98:25)
npm error     at async RegistryFetcher.manifest (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\lib\registry.js:128:23)
npm error     at async #fetchManifest (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1213:20)
npm error     at async #nodeFromEdge (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1051:19)
npm error     at async #buildDepStep (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:915:11)
npm error     at async Arborist.buildIdealTree (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:182:7)
npm error     at async Promise.all (index 1)
npm error     at async Arborist.reify (C:\Users\zzxia\AppData\Roaming\npm\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:131:5) {
npm error   code: 'EPERM',
npm error   errno: 'EPERM',
npm error   syscall: 'mkdir',
npm error   path: 'D:\\Program Files\\nodejs\\npm-cache\\_cacache\\tmp',
npm error   type: 'system',
npm error   requiredBy: '.'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
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.
npm error Log files were not written due to an error writing to the directory: D:\Program Files\nodejs\npm-cache\_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
豚&紙箱豚&紙箱

Program Filesフォルダは管理者権限がないと書き込むことはできなさそうです。

D:\npm-cacheに変更したら普通ユーザーでもnpm --global cache verifyが実行できました。