0

The package-lock.json of an existing project has been deleted for whatever reason.

Trying to recreate it gives the following error

$ npm i --package-lock-only
npm ERR! Cannot convert undefined or null to object

npm ERR! A complete log of this run can be found in: C:\Users\onthe\AppData\Local\npm-cache\_logs\2023-05-25T14_48_07_317Z-debug-0.log

In the log file I can see the following

2843 verbose stack TypeError: Cannot convert undefined or null to object
2843 verbose stack     at Function.keys (<anonymous>)
2843 verbose stack     at module.exports (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-pick-manifest\lib\index.js:213:22)
2843 verbose stack     at RegistryFetcher.manifest (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:119:22)
2843 verbose stack     at async Promise.all (index 10)
2843 verbose stack     at async [buildDepStep] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1044:5)
2843 verbose stack     at async Arborist.buildIdealTree (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:207:7)
2843 verbose stack     at async Arborist.reify (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:159:5)
2843 verbose stack     at async Install.exec (C:\Program Files\nodejs\node_modules\npm\lib\commands\install.js:147:5)
2843 verbose stack     at async module.exports (C:\Program Files\nodejs\node_modules\npm\lib\cli.js:89:5)

$ node --version
v18.16.0

$ npm --version
9.6.5

The same error occurrs if I just do npm install

ontherocks
  • 1,747
  • 5
  • 26
  • 43
  • Does `npm ci` generate a correct package-lock or do you not want to run this? – Cody G May 25 '23 at 15:41
  • @CodyG I can use any command as long as my work gets done. I got `npm i --package-lock-only` from https://stackoverflow.com/questions/46653833/is-there-a-way-to-force-npm-to-generate-package-lock-json `npm ci` gives the following error `npm ERR! The 'npm ci' command can only install with an existing package-lock.json or npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1.` – ontherocks May 25 '23 at 15:46
  • do you have a `npm-shrinkwrap.json` file? If so delete it and try `npm ci` again – Cody G May 25 '23 at 15:48
  • @CodyG nope, no `npm-shrinkwrap.json` – ontherocks May 25 '23 at 15:48
  • Eh. Can you share your `package.json` in the question? Have you tried putting the `package.json` in a NEW directory by itself and running `npm i` ? – Cody G May 25 '23 at 15:49
  • @CodyG Tried putting `package.json` in a new folder and running `npm i` from within that folder. I get the same error. Just saw while googling that this error might occur if there is a package in `package.json` that doesn't exist anymore. Not sure how do I find out which package doesn't exist. – ontherocks May 25 '23 at 15:56
  • You can just search each package name on npmjs.com. But yeah installing each package manually is a next good step – Cody G May 25 '23 at 16:02

0 Answers0