Forum Discussion
Yeoman Scaffolding and Node_Modules
Every time I create a new Web Part using Yeoman (yo @micrsosoft/sharepoint) in NPM, I get a huge project including tons of node_modules. The folder adds up to almost 300. I have tested adding web parts under an existing application, however when you run gulp serve it seems to compile every web part under the parent.
Do most people just expect to have all of the node_modules for each web part they create, or is there a better development environment method to consider. Can I set my node_modules folder to be global somewhere, so whenever I scaffold up a new web part I don't get the mode_modules folder?
9 Replies
- Hi @Fredrick,
This is standard behaviour and the best approach for various reasons.
Each project (which can include 1 or more webparts) needs to have a node_modules folder. This ensures that who ever builds your project will have the same exact result. Global modules are not declared at the project level, which could open the possibility for issues related to module versions.
Trust me, issues with versions of global modules can be really hard to deal with
Hope this helps- Fredrick LassiterCopper Contributor
Thanks Joel. I have seen where some people include all of their web parts in one project. I think that it might be worth grouping my web parts into separate projects, vs putting them all in "one project". I like the idea of being able to use one node_modules folder for all of them, however I don't want that project to get corrupted from Node JS. I think that with a good back up and versioning tool, I can always jump back if all things break on me for some reason.
Yes, version control will give you the option to roll back if you introduce breaking changes. Git is amazing!
In terms of grouping the web parts, there isn't a right or wrong answer on my opinion. It will depend on what you are trying to achieve. For example, if I'm creating a web part that can potentially be reused for a different project, I will create that web part in isolation or grouped with other reusable web parts. Although, if I'm creating client specific web parts, that won't be reused on a different project (they may have business logic specific to that client for example) I would group them together.
Back to the node modules folder, if you are creating web parts in separate projects, I would again not recommend trying to use a shared node_modules folder across different projects as each project will start with the same dependencies, but evolve in different ways over time. Having a node_modules folder per project (and local to the project) is best practices and the default behavior.
But, if you still decide to give it a go, please post back here your findings as I (and possibly others) would be interested to know if that worked well
- Deleted
normally when you install a node module you add the -g flag and it puts in the global path rather than the local path.
npm install -g <node-module>
(Caveat - I have not used the SharePoint Webpart Yeoman install, so not sure of the behavior, but have done plenty of nodejs).
- Fredrick LassiterCopper Contributor
Thanks Stephen. Yes, I have read in Node.js you can customize the installation of various nodes that you need, however seems like this Yoeman generator just spits everything out! The Visual Studio method of developing the SPFx framework may not have the same behavior.