[Fixed] npm shows an error 'ENOENT: no such file or directory' when creating a react project – Npm

by
Ali Hasan
node.js npm npm-install npx reactjs

Quick Fix: To resolve this issue, manually create the missing directory using the following command:

mkdir %AppData%\npm

The Problem:

When attempting to create a new React project using npm, the user encounters the error message ‘ENOENT: no such file or directory, lstat ‘C:\Users\Username\AppData\Roaming\npm”. This error indicates that npm is unable to locate a necessary file or directory. The user seeks assistance in resolving this issue.

The Solutions:

Solution 1: Create the missing directory

The error message suggests that the directory `C:\Users\Username\AppData\Roaming\npm` is missing. To fix this, simply create the missing directory using the following command:

mkdir "%AppData%\npm"

This should resolve the issue and allow you to create a new React project using npm.

Solution 2: Reinstall npm

In this solution, a user was facing a similar issue while working on a Next.js project. To resolve this issue, they re-installed npm globally using the following command:

npm install npm -g

Additionally, the user encountered a similar error later on in the project. In that case, rebuilding the project using the following command resolved the problem:

npm run build

By reinstalling npm globally and rebuilding the project, the issue related to the error ‘ENOENT: no such file or directory, lstat ‘C:\Users\Username\AppData\Roaming\npm” was resolved.

Q&A

Why is npm showing me the error ‘ENOENT: no such file or directory’ when creating a react project?

Try creating the missing directory: ‘mkdir %AppData%
pm’

What did you do to fix the npm ‘no such file or directory’ error in your Next.js project?

To fix the npm error in my Next.js project, I installed npm globally using the command: ‘npm install npm -g’

Video Explanation:

The following video, titled "npm ERR! code ERESOLVE could not resolve FIX Node JS React ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... node js and react js in visual studio code is shown. ... npm err code enoent react | How to fix npm start not working error in React JS.