node_modules appears empty, you may need to run `npm install`
Asked Answered
F

4

15

I have cloned an Angular 4 project from git.

When I go to the root folder of the project and executed ng serve.

I am getting following error:

node_modules appears empty, you may need to run `npm install`

How can I fix the above error?

Former answered 3/11, 2017 at 14:9 Comment(6)
so did you run "npm install" where your package.json is?Criswell
I have fixed above error by doing npm install command.Former
Note that it's useful to read the error message, rather than just copy-pasting it into Stack Overflow.Parishioner
My doubt is , I have already installed npm globally, why is it not taking that one. Should I install npm for each and every project.Former
Sorry @jonrsharpe, I am new to npm and node.Former
To install npm globally only enables you to run its commands from every directory, node modules are always project specific. There for package.json has to be always present in the root directory of your project.Giaour
H
22

Run npm install from the root of the project. If you're on a mac then you may want to run sudo npm install in case some if the package installations require elevated permissions. If it has submodules then leave a comment below and I'll update this answer to include how to deal with those. No use in confusing this answer with that unless you hit it.

Hart answered 3/11, 2017 at 14:11 Comment(2)
I hate to break the chain here, but I was getting the same issue and npm install or sudo npm install wasn't working. The key is to sudo rm -rf node_modules/ FIRST, then npm install will work fine. Make sure to sudo removeCabrera
If you had to delete the node_modules folder first then it existed. And based on the command you used it wasn't empty. What symptom did you have?Hart
C
1

If it's saying node_module is empty, it means it's not getting the path.

First of all, check the path. Go to that path using the cd command, such as:

cd C:\Windows\UrProjectName

After that, run ng serve in node using the Command Prompt (Windows).

Coelostat answered 9/2, 2018 at 7:46 Comment(1)
That advice to check the path by cd'ing to the project directory is what solved the problem for me. I was still in the parent directory after creating the Angular project via ng new. I needed to change to the newly created project directory before calling ng serveWeasel
B
0

Open the directory where your project is using:

cd Project_Name

Then, run the following command:

npm install

After that, you can then easily run the ng g component command.

Bolide answered 12/1, 2018 at 13:22 Comment(0)
T
-1

In this situation you should right click the app.component.html module, then click "open in terminal".

After the terminal is opened at the bottom, all you need to do is type the following command:

ng serve

It should now work properly. Every time you run the project and use this method, you will be able to avoid these types of errors.

Touristy answered 8/5, 2018 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.