# Error Installation Next JS

**URL:** <https://forum.codewithmosh.com/t/error-installation-next-js/23396>\
**Category:** Next.js\
**Created:** [November 1, 2023, 10:44am UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396 "2023-11-01T10:44:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![moeundara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/moeundara/32/7216_2.png) [@moeundara](https://forum.codewithmosh.com/u/moeundara)\
**Post date:** [November 1, 2023, 10:44am UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/1 "2023-11-01T10:44:52Z")

</div>

![Screenshot 2023-11-01 at 5.43.13 PM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/0/0da5a67e8b53319de31e04be4bc8639b724a0e2d.jpeg)  
Hello please help with this error. I tried to install new next js project, but error message shown like picture above.

---

<div class="post-metadata">

**Author:** ![JerryHobby](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jerryhobby/32/5370_2.png) [@JerryHobby](https://forum.codewithmosh.com/u/JerryHobby)\
**Post date:** [November 1, 2023, 12:32pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/2 "2023-11-01T12:32:15Z")

</div>

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

.

---

<div class="post-metadata">

**Author:** ![Programmist](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/programmist/32/7006_2.png) [@Programmist](https://forum.codewithmosh.com/u/Programmist)\
**Post date:** [November 2, 2023, 4:41am UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/3 "2023-11-02T04:41:07Z")

</div>

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:

```auto
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:

```bash
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.

---

<div class="post-metadata">

**Author:** ![moeundara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/moeundara/32/7216_2.png) [@moeundara](https://forum.codewithmosh.com/u/moeundara)\
**Post date:** [November 3, 2023, 4:12pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/4 "2023-11-03T16:12:27Z")

</div>

Thank you for helping. I will feedback after run npm install 😊

---

<div class="post-metadata">

**Author:** ![moeundara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/moeundara/32/7216_2.png) [@moeundara](https://forum.codewithmosh.com/u/moeundara)\
**Post date:** [November 3, 2023, 4:34pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/5 "2023-11-03T16:34:05Z")

</div>

> [@Programmist](#):
>
> ls -al /Users/moeundara | grep .npm

 ![Screenshot 2023-11-03 at 11.30.18 PM](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/3/3a43f9dd8c7a3d976f6191f93a95894030b506f2.jpeg)

Thank you for your help, now I face with another issue

---

<div class="post-metadata">

**Author:** ![moeundara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/moeundara/32/7216_2.png) [@moeundara](https://forum.codewithmosh.com/u/moeundara)\
**Post date:** [November 3, 2023, 4:40pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/6 "2023-11-03T16:40:13Z")

</div>

Thank you now I solved it by using:  
sudo npx create-next-app@latest  
sudo npm run dev

---

<div class="post-metadata">

**Author:** ![moeundara](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/moeundara/32/7216_2.png) [@moeundara](https://forum.codewithmosh.com/u/moeundara)\
**Post date:** [November 3, 2023, 4:42pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/7 "2023-11-03T16:42:16Z")

</div>

> [@moeundara](#):
>
> sudo npx create-next-app@latest  
> sudo npm run dev

now I fixed it  
sudo npx create-next-app@latest  
sudo npm run dev

---

<div class="post-metadata">

**Author:** ![Programmist](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/programmist/32/7006_2.png) [@Programmist](https://forum.codewithmosh.com/u/Programmist)\
**Post date:** [November 3, 2023, 4:47pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/8 "2023-11-03T16:47:05Z")

</div>

> [@Programmist](#):
>
> `sudo chown -R username:group /Users/moeundara/.npm`

The reason you got that “`illegal username`” error was because you forgot to replace `username` with `moeundara` and `group` with `staff`, so:

```auto
sudo chown -R moeundara:staff /Users/moeundara/.npm

```

---

<div class="post-metadata">

**Author:** ![Programmist](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/programmist/32/7006_2.png) [@Programmist](https://forum.codewithmosh.com/u/Programmist)\
**Post date:** [November 3, 2023, 4:56pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/9 "2023-11-03T16:56:06Z")

</div>

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

```bash
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:

```bash
sudo chown -R moeundara:staff /Users/moeundara/.npm

```

---

<div class="post-metadata">

**Author:** ![ILeads](https://avatars.discourse-cdn.com/v4/letter/i/ed8c4c/32.png) [@ILeads](https://forum.codewithmosh.com/u/ILeads)\
**Post date:** [November 15, 2023, 11:53pm UTC](https://forum.codewithmosh.com/t/error-installation-next-js/23396/10 "2023-11-15T23:53:38Z")

</div>

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.
