npm npx command fails (errno -4058)

この記事は約4分で読めます。
スポンサーリンク

Things I want to do

When I ran the npm/npx command, I received the error errno -4058 and it failed.

in particular

npx create-next-app@latest

The following error was displayed when I ran it:

npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\XXXXXXXXX\AppData\Roaming\npm
npm error errno -4058
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\XXXXXXXXX\AppData\Roaming\npm'
npm error enoent This is related to npm not being able to find a file.
npm error enoent
npm error A complete log of this run can be found in: C:\Users\XXXXXXXXX\AppData\Local\npm-cache\_logs\2024-09-22T06_50_41_859Z-debug-0.log

XXXXXXXXX is the username.

スポンサーリンク

Solution

Here are two solutions.

Doing just one thing won’t necessarily solve the problem, so if one method doesn’t work, you should try both.

Terminate the application running the Node.js server.

It seems that applications running the Node.js server (applications that execute commands like `npm run dev`) can sometimes interfere.

Examples include Command Prompt, PowerShell, and Visual Studio Code.

First, close these applications and then run the failed npm/npx again.

Installing npx

Install npx by running the following command from the command line or similar.

npm i -g npx

Run the failed npm/npx again.

Even if npx is available in other projects, it cannot be used in projects other than the one in which it was installed unless it was installed with the -g option.

Therefore, even if you have successfully executed npx before, it’s a good idea to try it again.

スポンサーリンク

Result

In my environment, simply closing Visual Studio Code didn’t solve the problem; I had to install npx afterward to resolve it.

スポンサーリンク

Websites I used as references

【Next.js】プロジェクトを作成しようとした際に発生したエラーの解消法 - Qiita
背景 新しいPCに買い替えたのでNext.jsの勉強をしようと思い、 プロジェクトを作成しようとしたが、エラー発生。 環境 Node.js:20.10.0 エラー内容 npx create-next-app@latestでプロジェクトを作成しようとした際に、 次の...
npm installがENOENTとか変な失敗をするとき、VS Codeを閉じると良いかも。 | Ginpen.com

コメント

タイトルとURLをコピーしました