Last updated: Apr 4, 2024
Reading time·2 min

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.
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.
npm install

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.
yarn install
After you run the npm install command, the node_modules folder will be
generated in the root directory of your project.

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.
npm start
Or by running npm run dev, depending on the scripts section of your
package.json file.
npm run dev
If the error persists, try to clear your cache before installing your modules.
# clear your cache npm cache clean --force # install your dependencies npm install
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.
# 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.
# 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.
npm start
Or by running npm run dev, depending on the scripts section of your
package.json file.
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.