Dependencies from package.json are missing after install

Understand why dependencies may not being installed during a build and how to fix.
Last updated on September 30, 2024
Build

For Node.js projects it is a common practice to store external dependencies for a project in package.json file. These dependencies are managed by the package manager of your choice (See supported package managers on Vercel) and are installed automatically during a build on Vercel.

A typical package.json file splits dependencies between dependencies and devDependencies. The convention is to list runtime dependencies under dependencies and build-time dependencies under devDependencies.

package.json
{
  "name": "my-app",
  "dependencies": {
    "next": "latest",
    "react": "latest",
    "react-dom": "latest"
  },
  "devDependencies": {
    "@types/node": "latest",
    "@types/react": "latest",
    "typescript": "latest"
  }
}

Vercel installs the dependencies defined in your package.json at the start of your build. However, depending on your project configuration, some dependencies might not get installed.

For example, dependencies listed in the devDependencies section might be missing, leading to an error like this:

It looks like you're trying to use TypeScript but do not have the required package(s) installed.
Please install typescript and @types/node by running:
npm install --save-dev typescript @types/node

Even though you defined the missing dependencies in the devDependencies section of your package.json, they might not be resolved during the build.

Many package managers offer a production mode for their install command, which installs only the dependencies listed under dependencies, ignoring those in devDependencies.

You can enable production mode by passing a flag to the install command, or it activates automatically when the NODE_ENV=production environment variable is set.

Setting this environment variable in your project settings makes it available during both the build phase and when running your app on Vercel.

If NODE_ENV is set in the project settings, it will be available during dependency installation, which may trigger production mode.

Removing the NODE_ENV environment variable from the project settings would resolve this issue, but there may be cases where you want to keep it.

In such cases, you can prevent the package manager from using production mode during installation by modifying the Install Command in your project's Build & Development Settings.

Configure a custom install command in the project settings
Configure a custom install command in the project settings

Depending on the package manager you are using in your project you have to use a different command:

To disable the production mode for the npm CLI, you have to add the flag --production=false to the install command (documentation):

npm install --production=false

To disable the production mode for pnpm, you have to add the flag --prod=false to the install command (documentation):

pnpm install --prod=false

To disable the production mode for Yarn, you have to add the flag --production=false to the install command (documentation):

yarn install --production=false