I cloned a repository from github which has a package-lock.json (but no package.json). Then in a git bash terminal I go to the directory and run npm install but I just get a message saying there is no package.json and then everything in package-lock.json gets deleted so it's basically empty except for the project name and version.
I thought running npm install with a package-lock.json in the directory was enough to re-create node_modules, but am I seriously misunderstanding how this works? By the way I have node 8.12.0 and npm 6.4.1 and am running on Windows 10. Also, I think the package-lock.json was created on a unix system so could there be problems when using package-lock.json on a different OS?
I already tried running npm init just to get a package.json file and then running npm install but that still didn't get me a node_modules folder.
AFAIK, the
package-lock.jsonfile relies on the presence of apackage.jsonfile, so you'll not be able to recreate yournode_modulesfolder from thepackage-lock.jsonfile alone (happy to be proved wrong here).Therefore, your best bet is to (mis)use a module like auto-install that is capable of generating the
package.jsonfile based on a project's dependencies, as they appear in the files.Install it globally (
npm install -g auto-install), then you'll need to generate an emptypackage.jsonfile for it to run (usenpm init -yin your project root). Kick things off with the commandauto-installand it should add the dependencies to thepackage.jsonfile.HTH