Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should changes in a package.json file be commited to a repository as well?

Tags:

I am not sure that if it is correct to commit and push the changes in the package.JSON file into a repository. as far as I understood, the others in the git can install new dependencies by executing this command: npm install and accordingly, their package.JSON will be updated too.OR, this files actually says what are the new dependencies and needs to be pushed as well. It would be great if some could clarify me. :)

like image 676
Maryam Koulaei Avatar asked Sep 12 '17 10:09

Maryam Koulaei


People also ask

Should package json be committed?

json file needs to be committed to your Git repository, so it can be fetched by other people, if the project is public or you have collaborators, or if you use Git as a source for deployments. The dependencies versions will be updated in the package-lock.

What does repository do in package json?

The repository property of a package. json is an array that defines where the source code for the module lives. Typically, this would be a public GitHub repo for open source projects, with the repository array noting that the type of version control is git and the URL of the repo itself.

Should package lock json be updated?

package-lock. json is updated automatically on dependency changes. It should be committed to version control to ensure the same dependencies on install.


2 Answers

You need to commit package.json. All other developers, after pulling the code, will just need to perform npm install to get the latest dependencies required for the project.

Whenever you or someone else wants to add new dependencies to the project you perform npm install --save or npm install --save-dev. Then package.json is automatically updated, and needs to be committed again.

Note: dependencies should not be committed, so you need to add node_modules to the .gitignore file (supposing you use git), and commit this file also.

like image 106
Marinos An Avatar answered Sep 20 '22 12:09

Marinos An


It depends, are the packages that were added to the package.json file required for the application to run?

If not, then no. For packages that are not required to run then use the following command:

npm install {package} --saveDev 

This saves the package to the package.json file as a development package and not something that is required to run the app.

You dont have to commit changes unless they are necessary.

like image 22
Lars Peterson Avatar answered Sep 20 '22 12:09

Lars Peterson