Hello please help with this error. I tried to install new next js project, but error message shown like picture above.
It’s hard to tell what went wrong with certainty. The most common issue is you forgot to run
npm install
before you ran
npm run dev
.
It seems like you might not have correct ownership or permissions set for your /Users/moeundara/.npm directory. Try running ls -al /Users/moeundara | grep .npm and see what you get. When I run this on my home directory I get:
drwxr-xr-x 12 tony staff 384 Oct 4 20:07 .npm
Note my username (tony) and group (staff). If you run this command and see root instead of your username you’ll need to change ownership recursively for the .npm directory and its subdirectories using the chown command:
sudo chown -R username:group /Users/moeundara/.npm
where username and group are your username and group (moeundara and probably staff).
That’s one possibility. This could also be a permissions issue, but I would try this first.
Thank you for helping. I will feedback after run npm install ![]()
Thank you now I solved it by using:
sudo npx create-next-app@latest
sudo npm run dev
now I fixed it
sudo npx create-next-app@latest
sudo npm run dev
The reason you got that “illegal username” error was because you forgot to replace username with moeundara and group with staff, so:
sudo chown -R moeundara:staff /Users/moeundara/.npm
now I fixed it
sudo npx create-next-app@latest
sudo npm run dev
This may be an issue for you because when you used sudo to run create-next-app it probably created the project directory owned by root. This means that you’ll have to use sudo to run VSCode or it won’t be able to add, change, or delete files in the project, which is a nuisance.
My advice here is to run sudo chown -R moeundara:staff on whatever your project directory name is. So if you called it my-project you would run:
sudo chown -R moeundara:staff my-project
Also be sure to run it on the .npm directory to make sure you’ve fixed the original problem:
sudo chown -R moeundara:staff /Users/moeundara/.npm
The “illegal username” error occurred because you omitted to substitute “username” with “moeundara” and “group” with “staff.” Ensure these replacements are made to resolve the issue.

