Visual Studio MVC 5 web project - should I include "node_modules" folder in project?

1.3k Views Asked by At

I use NPM to maintain front-end dependencies in my MVC 5 web project. One of the key uses I have for NPM is to get Typescript definitions for things.

The project is organised like this:

MySolution
|
|-- MySolution.Web
    |
    |-- Controllers
    |-- node_modules
    |-- Views
    |-- (etc...)

What I want to know is if I should be including "node_modules" into the project, and if I should be including "node_modules" into source control.

The reason I ask is that everything seems happy with it being excluded (even the build agent, which does a "NPM restore" before compiling).

However, NCrunch is complaining that it can't find any reference to various types which my project's TypeScript files make reference to.

E.g. Admin.ts makes reference to "/node_modules/@types/knockout/index.d.ts"

I think that bringing in "node_modules" into the web project would fix it, but I'm not sure if it's right.

1

There are 1 best solutions below

1
On BEST ANSWER

no, you shouldn't include this in source control or the project.

assume you do a full clone, from scratch, the first you would do is an npm install which would restore all packages and populate that folder anyway. It's exactly the same reason why you do not add things like NuGet packages either.

that folder can easily get very big and delay your CI/CD pipeline. As you said yourself, running npm install is something that can be done automatically anyway. If you download a git ignore file for Visual Studio for example, it will come with stuff like that ignored by default and for good reason.

As far as your typescript files are concerned, those should be fine as well. You'll do the restore first anyway before doing any work and you can use something like Visual Studio Code to work with your front end files and it doesn't matter if the node modules are part of your solution or not.