Unable to use npm for `vercel dev` in local. Uses yarn instead

Running Vercel CLI 43.2.0, not using Corepack. The app itself is an express web server.

I’m running into an issue where vercel dev in local isn’t using npm and instead tries to use yarn. I don’t have a yarn.lock and I have a package-lock.json. However, when I make a push to prod it does use npm somehow.

I have also tried adding npm install as the Install Command in the vercel UI settings, but that it still doesn’t seem to be working either. I only have this one project so I don’t think it’s being connected to any other instance. I assume that the Install Command would override whatever local commands there are.

This is what my vercel.json looks like

{
  "version": 2,
  "rewrites": [{ "source": "/(.*)", "destination": "/api" }],
  "installCommand": "npm install",
  "buildCommand": "npm run build"
}

I have also deleted the project and readded it and it looks like it gets gets the npm from vercel.json when initializing but then runs yarn

The vercel dev command automatically detects your package manager based on lock files in your project. But a few other configuration options could interfere with that.

Here are a few things to check:

  1. Make sure there’s no yarn.lock file in your project root or any parent directories
  2. Make sure there is a package-lock.json file in your project root
  3. Update to the latest version of the CLI, currently 43.3.0, by running npm i -g vercel@latest
  4. Check if you have a vercel.json with and installCommand that might be forcing yarn

Please give that a try and let me know how it goes :slightly_smiling_face:

It must be some weird issue bc I followed all these steps and still not working. I also tried running vercel dev on a diff project and it installed npm but not for this one somehow

Here’s my project structure

Here’s my vercel.json

And I updated to v43.3.0 and still get the error
image

I wasn’t able to replicate this error with my projects. There may be something, like a package dependency, that’s causing this with your project. Does this happen when you try to run other projects?

Do you also get a yarn error on a minimal project like GitHub - amyegan/express-vercel ?

Solution: Remove the conflicting “dev” script from package.json

I had the same issue and found the root cause! The problem was having a "dev": "vercel" script in my package.json that was causing a conflict.

The Issue

When you have this in your package.json:

"scripts": {
  "dev": "vercel",  // <-- This causes the yarn fallback
  "build": "echo 'Static files ready'",
  "deploy": "vercel --prod"
}

Running vercel dev creates a circular dependency because the CLI tries to run npm scripts, finds the “dev” script that calls “vercel”, and falls back to yarn detection.

The Fix

Simply remove or rename the conflicting “dev” script:

"scripts": {
  "build": "echo 'Static files ready'",
  "deploy": "vercel --prod"
}

How I Found This

  1. Tested with the example repo @amyegan provided (express-vercel) - couldn’t reproduce the issue there
  2. Compared my package.json with the working example
  3. Identified the “dev” script as the difference
  4. Created a minimal reproduction repo: yarn-command-not-found-vercel
  5. Confirmed removing the “dev” script fixed the issue

Context

I’m hosting static files and most of my setup was generated using Claude Code, which is why it took me a while to identify this issue. Hope this helps others who run into the same problem!