0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

npx create-next-app後にnpm run devが動かない?依存関係エラーの原因と解決方法

Posted at

Next.js プロジェクトを npx create-next-app@latest で作成した直後に、
npm run dev を実行してもエラーが出て開発サーバーが起動しないことがあります。

❌ エラー発生状況

以下のようなエラーが表示されるケースです。

$ npm run dev

> my-app@0.1.0 dev
> next dev

sh: 1: next: not found

🔎 主な原因

  1. 依存関係(node_modules)が正しくインストールされていない

    • ネットワークエラーや途中キャンセルで npm install が失敗した場合。
  2. インストール時にエラーを見落とした

    • 途中で ERR! などが出ているのに気づかず、そのまま進めてしまった場合。

🛠 解決方法

1. 依存関係を再インストール

プロジェクトルートで以下を実行します。

rm -rf node_modules package-lock.json
npm install

その後、再度起動します。

npm run dev

2. npx create-next-app を再実行

もし依存関係が壊れている場合は、プロジェクトを削除してもう一度作り直すのが早いです。

npx create-next-app@latest my-app
cd my-app
npm run dev

✅ まとめ

  • node_modulespackage-lock.json を削除して npm install し直すのが解決の近道
  • 最悪の場合でも、再度 create-next-app を実行すれば環境を立て直せます

これで npm run dev が正常に動作するはずです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?