0

In the parent folder of my create-react-app folder I deleted the package-lock.json and node-modules file by mistake. I tried using npm install but it did not work and only created an empty package-lock.json file. How do I undo this? Please help.

By parent folder I mean the folder in which I typed create-react-app myApp and in which the myApp folder gets created

Odasaku
  • 177
  • 6
  • 17
  • npm install will look at your npm-shrinkwrap.json then to package-lock.json for the dependencies to install. https://docs.npmjs.com/cli/v7/commands/npm-install thats why everything is empty after running that command, because npm has nothing to tell it what to get. Do you have a version of your package-lock.json in git you can pull? You may be able npm init again https://docs.npmjs.com/cli/v6/commands/npm-init – brooklynDadCore Mar 19 '21 at 17:43
  • this has been alreacheck [this question](https://stackoverflow.com/questions/57223024/accidentally-deleted-package-json-is-there-anyway-for-you-to-regenerate-it) – coldhands314 Mar 19 '21 at 17:43
  • 1
    Deleting **package-lock.json** and **node_modules** is never a problem. Do you have **package.json** file? To regenerate lock file and node modules, you need to do `$ npm i` inside `myApp` directory. – Ajeet Shah Mar 19 '21 at 18:11
  • I tried `npm i`but it did not work. Instead it threw the error that react-router-dom couldn't be resolved and started working after I ran `npm i react-router-dom`. Any idea why this happens? As in why can't `npm i` also install react-router-dom along with other dependencies – Odasaku Mar 20 '21 at 18:13
  • Does `package.json` file have `react-router-dom` in its dependencies block? – Ajeet Shah Mar 20 '21 at 18:25

0 Answers0