Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Forcing an NPM Restore

DZone's Guide to

Forcing an NPM Restore

Facing a situation where you need NPM to restore your packages, especially if you're a Visual Studio user? Then this is your post.

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

I've recently started looking into the Javascript library React.js. Having read a couple of tutorials and watched the start of a Pluralsight video, I did the usual and started creating a sample application. The React.js template in VS is definitely a good place to start; however, the first issue that I came across was with NPM.

Upon creating a new web application, I was faced with the following errors:

Image title

The reason being that, unlike NuGet, npm doesn't seem to sort your dependencies out automatically. After playing around with it for a while, this is my advice to my future self on how to deal with such issues.

The best way for force npm to restore your packages seems to be to call

npm install

either from Powershell or from the Package Manager Console inside VS.

Powershell

Image title

On running this, I found that, despite getting the error shown above, the packages were still restored; however, you can trash that file:

Image title

Following that, delete the node_modules directory and re-run, and there are no errors:

Image title

Package Manager Console

In the Package Manager Console, ensure that you're in the right directory (you'll be in the solution directory by default, which is the wrong directory):

Image title

References

https://stackoverflow.com/questions/12866494/how-do-you-reinstall-an-apps-dependencies-using-npm

The post Forcing an NPM Restore appeared first on The Long Walk.

Take a look at the Indigo.Design sample applications to learn more about how apps are created with design to code software.

Topics:
npm ,web dev ,powershell ,visual studio

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}