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?
-
Have you tried `npm install`? – rtn Apr 26 '18 at 10:26
-
1I have but it gives me no package.json file found – Sandeep kurien Apr 29 '18 at 07:01
-
1Something not right with the theme because package.json is necessary to install other dependencies.. what’s the url of the theme ? – Johnson Samuel May 26 '18 at 16:38
-
possible duplicate of https://stackoverflow.com/questions/53858814/npm-to-create-a-package-json-file-out-of-the-package-lock-json-file – cangosta Feb 08 '19 at 20:32
4 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

- 140,023
- 84
- 646
- 689

- 1,556
- 18
- 26
-
36I tried it with the latest npm (`6.4.1`) and it doesn't work. It only creates a `package.json` file without any dependencies listed. – Amade Sep 02 '18 at 13:46
-
@Amade Interesting I was able to recover my packages with that command :/ – VeeeneX Sep 03 '18 at 08:12
-
-
3npm `6.6.0`. `package.json` does not include the existing packages listed in `package-lock.json` – Lin Du Jan 23 '19 at 02:57
-
46.9.0 and it is still not working, neither is npm ci - what is the point of this file's use in CI if it seems to be ignored ? – RuiDC Jun 21 '19 at 14:53
-
-
-
1
-
This wiped out my package-json. I've edited the question with a warning but I'm not knowledgeable enough about this to know what's going on or if it's just not possible. – Simon_Weaver Jun 13 '22 at 21:32
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.

- 552
- 5
- 11
-
1This is a perfect explanation. I cloned a project to local that included node_modules but not package.json, so I couldn't rebuild and deploy. This was the perfect solution to my issue. – billoverton Feb 28 '20 at 20:22
-
3This is perfect comment on situation, but it has nothing to do with answering to the question: `How do I install the node modules with just the package-lock.json file` – Kos Apr 11 '20 at 21:34
https://pravnyadv.github.io/unpackage/ seems to work. Copy your package lock file text in, hit the button, copy out the text into a new package.json file.

- 4,256
- 4
- 34
- 48
-
1
-
1
-
https://pravnyadv.github.io/unpackage/ may return your `package.json` a single line. If so and you'd like to unfurl it a multi-line format, pipe it into `jq` with: `echo '$your_package_blobl' | jq` – Alex Mapley Apr 29 '22 at 01:13
-
I am late here, but the above link: https://pravnyadv.github.io/unpackage/ is not working anymore, do you have any alternatives? – Mithun Shreevatsa Aug 29 '23 at 11:35
package-lock.json file relies on the presence of a package.json file, So it's not possible to retrieve package.json (happy to be proved wrong).
So a possible solution left is to use a module like auto-install which is capable of generating package.json from the project file dependencies.
First, you need to install the module globally npm install -g auto-install
. Then run npm init
and answer the basic requirements.
Then, run auto-install
in your project root directory. All the dependencies should reflect in package.json file.
**
Or Install node modules directly from package-lock.json
**
Run npm ci
which bypasses a package’s package.json to install modules from a package’s lockfile.

- 77
- 1
- 2
-
3`npm ci` always tells me "added 0 packages" and `auto-install` **rewrote my _package-lock.json_**, installed 2 random packages and stopped at "Watchers initialized"... _node_modules_ folder was created but only with these 2 packages... Glad I had a lock backup :( – CPHPython Apr 12 '19 at 13:24
-
4`npm ci` **depends** on `package.json` so it cannot be used with only `package-lock.json` present – Kos Apr 11 '20 at 21:36