Local package.json exists, but node_modules missing [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
2 min

banner

# Local package.json exists, but node_modules missing [Fixed]

The npm error "Local package.json exists, but node_modules missing, did you mean to install?" occurs when the node_modules directory in your project is missing.

To solve the error, run the npm install command.

shell
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

Open your terminal in your project's root directory (where your package.json file is) and issue the following command.

shell
npm install

install dependencies

Make sure your terminal is located in the same directory as your package.json file because that's where it reads your dependencies from.

If you use yarn to manage your dependencies, you can also use the yarn install command.

shell
yarn install

After you run the npm install command, the node_modules folder will be generated in the root directory of your project.

node modules folder generated

The npm install command installs the modules that are specified in the dependencies object of your package.json file.

Try to start your development server after installing your dependencies.

shell
npm start

Or by running npm run dev, depending on the scripts section of your package.json file.

shell
npm run dev

If the error persists, try to clear your cache before installing your modules.

shell
# clear your cache npm cache clean --force # install your dependencies npm install

# Delete your node_modules and package-lock.json files

If the error persists, try to delete your node_modules directory manually and recreate it by running npm install.

If you are on Windows, navigate to the root directory of your project (where your package.json file is) and issue the following commands.

cmd
# on Windows rd /s /q "node_modules" del package-lock.json del -f yarn.lock # 👇️ clean your npm cache npm cache clean --force npm install

If you are on macOS or Linux, navigate to the root directory of your project and issue the following commands.

shell
# on macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # 👇️ clean your npm cache npm cache clean --force npm install

Open the project in your IDE and make sure the node_modules folder exists in the root of your project.

Try to start your development server after installing the dependencies.

shell
npm start

Or by running npm run dev, depending on the scripts section of your package.json file.

shell
npm run dev

The node_modules directory gets automatically generated when you run the npm install or yarn install commands.

However, you have to make sure to run the npm install command from the root directory of your project (where your package.json file is), so it can read the dependencies it has to install.

After running the command, you should be able to start your development server without any issues.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.