npm init is a nice tool for initializing a package.json. Today I learned
that you should not use it on an existing JavaScript project!
This blog is a Go project, but I use JavaScript dependencies for development. My manifest looks like this:
// package.json
{
"scripts": {
"test:e2e": "cypress run",
"push": "npm run test:e2e && git push"
},
"devDependencies": {
"cypress": "^15.20.1",
"prettier": "^3.8.3"
},
"allowScripts": {
"cypress@15.20.1": true
}
}
I thought I could get away with running npm init on it to standardize the
file. When I did, the program looked in my node_modules directory and saw ~170
dependencies, most belonging to Cypress.
It then said: “These are dependencies that this project needs, that aren’t listed, so I’ll add them to the manifest.” My project’s dependencies then grew by ~170 😵💫.
npm init is for new projects only.
See npm help init for more.