Trouble with packages

My react app is showing two package.json and package-lock.json.

Intially it only has one package.json when i creat react app using npx create-react-app, but it adds another package whenever i install any dependencies.

Above-mentioned is the image of the file

Why is it showing two packages and what are the effects on the app

Building package-lock.json is part of building the application. You update package.json either manually or via npm commands to tell node what packages and versions to include, package-lock.json is an artifact of it actually doing that.

1 Like

The indentation of the files is hard to tell in the image but I’m pretty sure they are not in the same folder.

You have node_modules, package.json, package-lock.json in the api-1 folder and also in the folder above it (so inside the ../api-1 folder, so in the API APP1 folder).

Edit: Just to explain. When you run npm in a folder that folder is the “root” for the command. So you can run it in different folders

/root1
 node_modules, package.json, package-lock.json
  /root2
    node_modules, package.json, package-lock.json
1 Like

How can i use npm command?

The package in the API API1 folders shows up whenever i install any dependencies, and the dependencies do not work

Make sure the terminal is opened inside the correct folder when running npm. The terminal will show the folder/path you are on.

If you run an npm command that creates files/folders inside the API APP1 folder the terminal is opened inside that folder.

In the terminal, you can cd into the child folder using cd api-1 and back up again using cd ..

1 Like

Okay. I’ll give a try. Thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.