Runtime Error: "Cannot find module 'axios'" despite successful build

Current behavior: When I send a POST request to my /api/webhook function, the deployment fails with a 500 status code. The runtime log for the function shows the error: Cannot find module 'axios'. This happens consistently on every deployment.

Expected behavior: The /api/webhook function should execute successfully, find the axios module, and return a 200 OK status after forwarding the request.

This issue can be reproduced by deploying a project with the following package.json and a simple function that imports axios.

package.json:

JSON{ "name": "cblc-proxy", "version": "1.0.0", "license": "ISC", "dependencies": { "@vercel/kv": "^3.0.0", "axios": "^1.7.2" } }

/api/webhook.js:

`JavaScriptimport axios from ‘axios’;

export default async function handler(req, res) {
// The function fails before this code can even run properly
// due to the missing module.
res.status(200).json({ message: “Hello world” });
}`

What I’ve already tried without success: I have performed extensive troubleshooting, and the issue seems to be with the Vercel build/runtime environment itself, because:

  • Source Tab is Correct: I have confirmed in the “Source” tab of the failed deployment that the package.json file is correct and includes axios.
  • Build Cache is Disabled: I have confirmed all deployments were triggered with the build cache disabled.
  • Root Directory is Correct: The “Root Directory” project setting is empty, which is the correct configuration.
  • Build Logs Show Success: The build logs show that the dependency installation completes successfully. It includes the line added 26 packages in 2s.
  • package-lock.json was Regenerated: As a final test, I deleted package-lock.json, ran npm install locally on a fresh clone to generate a perfect package-lock.json, and pushed it. The new deployment using this file still fails with the exact same runtime error. I also confirmed the regenerated package-or.lock.json is visible in the “Source” tab of the latest failed deployment.

This proves the issue is likely not with my code configuration but with how the Vercel runtime environment is being provisioned. The node_modules directory does not seem to be available to the function at runtime.

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