Someday I just got curious about node_module in framework or UI libraries such as React. After searching some stuff, I found there should be no changes in node_modules unless the user really needs to, so here's my questions.
- Why there shouldn't be changes in
node_modules? - Even I change the code, there were no change in result. Why does this happen? Even deleting the file or folder inside
node_modulesthere were no changes. (I thought it should show an error, but it worked Ok...) - When we start the framework (like
npm startin React), does NPM downloads the external files for example from Github everytime and places in the DOM? If that's right, the files innode_modulesare just readable ones?
Could someone give me an answer?
CodePudding user response:
node_modulesare the libraries / packages / modules (whatever name you call) written by the open source community. They can be inter-depending. If you change one of those files without reviewing the impact to their dependent, the execution of code may crash.However, not every single file or every single line of codes are required for each execution of code. Most of the time, one package can do things way more than what your code truly needed. If your code doesn't depend on the files that you changed, your project can still run happily.
npm startdoesn't download files automatically.npm installdoes. So files innode_modulesare not readable only. However, in many case, files innode_moduleswere ignored fromgit commit. In server environment, packages are freshly pulled from remote, instead of from your local machine. Therefore your changes to packages would not be deployed unless you explicitly do so.
Technically you can modify the files in node_modules and NOT running npm update forever - not a good commercial practice. Acceptable for personal project, if you are the sole programmer and can fully control when to update packages.
CodePudding user response:
- Well, if you change your node module an npm update will eventually overwrite your code and you will lose your functionality possibly even without knowing where the problem is.
