I got several issues after I deleted package-lock.json and node_modules, and figured out that I installed a lot of packages without --save or --save-dev.
I am now wondering how to fix this. Some of my packages are not even needed in my project.
I need to identify which packages are useful, so i used depcheck https://www.npmjs.com/package/depcheck which doesn't exactly work as I would like it to because some "unused devDependencies" are actually used, and I don't think the missing dependencies are here...
depcheck .
unused dependencies
depcheck
instafeed.js
leaflet
leaflet.icon.glyph
v-autocomplete
vue2-leaflet
unused devDependencies
autoprefixer
browser-jsonp
css-mqpacker
cssnano
gulp
gulp-postcss
gulp-sass
laue
lodash.orderby
postcss-assets
resolve-url-loader
sass
sass-loader
v-datatable-light
vee-validate
vue-bootstrap-datetimepicker
vue-country-region-select
vue-instagram
vue-resource
vue-slider-component
vue-stack-grid
vue-star-rating
vue-tel-input
vuejs-datepicker
missing dependencies
laravel-elixir
react
react-dom
For example I got a loat of errors refering to postcss-loader, css-loader, style-loader etc and these don't appear at all here. And my project is in vuejs so i don't get what react is doing here...
So i would like to identify the missing packages (from package-lock.json maybe?) with their actual version, and save them in package.json.
Is this posisble?
Thanks a lot, these would save my life :D
EDIT: I saw this post How to npm install --save all packages already installed? and something like this npm install ls node_modules
--save would be a good start, but I would like to add a version (doesn't work anymore)
[EDIT] Thanks for your answers, I added this in a test.js file and executed it (node test.js)
const fs = require('fs');
const packageLock = require('./package-lock.json');
const package = require('./package.json');
package.dependencies = Object.entries(packageLock.dependencies)
.reduce((deps, [dep, { version }]) => Object.assign(deps, { [dep]: version }), {});
fs.writeFileSync('./package-new.json', JSON.stringify(package, null, 2));
Now I have a file containing all dependencies and can just add the necessary ones to my package.json file.