Resolve NPM error: node_modules appears empty, you may need to run npm install

Learn how to fix the error node_modules appears empty, you may need to run npm install with NPM

Posted on May 12, 2022


When trying to run an Angular or Ember application using the serve command, you may face an issue that says the node_modules/ folder appears empty.

Here’s an example of the error when running the ng serve command:

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

Or its alternative as shown below:

$ ng serve
Node packages may not be installed. Try installing with 'npm install'.
Could not find the '@angular-devkit/build-angular:dev-server' 
builder's node package.

This error happens when there are missing packages in your node_modules/ folder that prevents the development server from running.

To solve this error, you need to make sure that you have the node_modules/ folder generated by the npm install command.

For old Angular or Ember versions, you may need to perform npm install manually after running the ng new or ember new command.

Change the active directory of your command line using the cd command to the folder where you create the application.

Here’s an example of running npm install on an Angular project named ng-app:

$ ng new ng-app
✔ Packages installed successfully.
    Successfully initialized git.
$ cd ng-app
$ npm install

For the latest Angular or Ember versions, you don’t need to perform an npm install because the CLI already runs the process for you.

Once the installation is finished, change the terminal’s active directory to your generated project. Try to run the ng serve or ember serve command again from there.

If you still see the error after npm install, then you may have some packages uninstalled because of an unknown error.

Try to run npm install with the log-level set as verbose as shown below:

npm install --loglevel verbose

You may see an error caused by one of the packages that fail to install.

Also, please make sure that you have enough memory to perform the installation. Running out of memory in the middle of the installation process can cause the same issue.

You can increase the memory allocated when running the npm install command as shown below:

# run npm install command with 2GB memory
node --max-old-space-size=2048 `which npm` install

# run npm install command with 4GB memory
node --max-old-space-size=4096 `which npm` install

The command above should help you allocate enough memory to run the npm install process.

I hope this tutorial has helped you resolve the node_modules appears empty issue. 🙏

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.