Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create package.json from package-lock.json

I downloaded a theme and it has a package-lock.json file but no package.json file. Is there a way I can generate the package.json from the package-lock.json file. How do I install the node modules with just the package-lock.json file. Is there a way to do that?

like image 844
Sandeep kurien Avatar asked Apr 26 '18 08:04

Sandeep kurien


People also ask

Does package json generate package lock?

Description. package-lock. json is automatically generated for any operations where npm modifies either the node_modules tree, or package. json .

What should I do with package lock json?

The package-lock. 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. json file when you run npm update .


2 Answers

Warning: Do not attempt before reading comments below & backup package-lock.json.

Install the latest npm with npm install -g npm

Run npm init and respond to the questions.

The above command will generate a package.json and include the existing packages listed in package-lock.json

like image 71
VeeeneX Avatar answered Oct 08 '22 14:10

VeeeneX


I think I figured it out.

I don't think npm init can draw from package-lock.json. However it does seem to pull from what is already in your /node_modules. I believe this is why @Harry B's solution works for some and not at all for others.

For example, if you have just cloned your project which contains package-lock.json, no package.json, and empty/non-existence node_modules, npm init won't create any dependencies. However, if you run npm install pkg1 pkg2 pkg3 ... then run npm init it will create the dependencies in package.json.

like image 25
Paul Avatar answered Oct 08 '22 16:10

Paul