3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSコードのターミナルでnpm run dev実行時の、Error: Cannot find module @rollup/rollup-darwin-x64 の解決方法

Posted at

はじめに

瑣末なことですがはまったのでメモします。

問題

vsコードのターミナルでnpm run devできない
エラー文に従い、node_modulesを一旦消してnpm iをしてもダメ

・自分の中での、vsコードのターミナルとiTermの使い分け
npm run devはvsコードのターミナルでやるようにしていた
それ以外のコマンドは、iTermでやる(ログを取るのはiTermでやりたい)
そのため、iTermでnode_modulesを一旦消してnpm iを実行していた

コマンド
rm -rf node_modules package-lock.json
エラー
% npm run dev

> sample-vite@0.0.0 dev
> vite

/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js:59
                throw new Error(

Error: Cannot find module @rollup/rollup-darwin-x64. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
    at requireWithFriendlyError (/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js:59:9)
    at Object.<anonymous> (/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js:68:76)
    ... 3 lines matching cause stack trace ...
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at cjsLoader (node:internal/modules/esm/translators:366:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24) {
  [cause]: Error: Cannot find module '@rollup/rollup-darwin-x64'
  Require stack:
  - /Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js
      at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
      at Module._load (node:internal/modules/cjs/loader:984:27)
      at Module.require (node:internal/modules/cjs/loader:1231:19)
      at require (node:internal/modules/helpers:179:18)
      at requireWithFriendlyError (/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js:41:10)
      at Object.<anonymous> (/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js:68:76)
      at Module._compile (node:internal/modules/cjs/loader:1369:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
      at Module.load (node:internal/modules/cjs/loader:1206:32)
      at Module._load (node:internal/modules/cjs/loader:1022:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
      '/Users/xxx/yyy/zzz/node_modules/rollup/dist/native.js'
    ]
  }
}

解決方法

・コマンド実行場所を変更
iTermで、node_modulesを一旦消してnpm iをする
→ vsコードのターミナルでnpm run devを実行できない

vsコードのターミナルでnode_modulesを一旦消してnpm iをする
→ vsコードのターミナルでnpm run devを実行できた

おわりに

想定外のことで、参りました。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?