---
title: Why does my Serverless Function work locally but not when deployed?
description: Learn how to troubleshoot your Serverless Functions.
url: "https://vercel.com/kb/guide/why-does-my-serverless-function-work-locally-but-not-when-deployed"
published: 2025-11-03
last_updated: 2026-10-16
authors: Lee Robinson
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---

There are a few nuances with [Vercel Functions](https://vercel.com/docs/functions) that may cause them to work in your local environment, but not when deployed. Read on to learn how to troubleshoot such a situation.

## Native dependencies

One of the common reasons for different behavior across environments is whether or not your Vercel Functions depend on packages with native dependencies. Native in this context refers to software that needs to be compiled and integrated with JavaScript through a layer like [node-gyp](https://github.com/nodejs/node-gyp).

A great example of such a package is the [bcrypt](https://www.npmjs.com/package/bcrypt) library which is a popular choice for encrypting passwords. You might be able to install `bcrypt` without issues on your local machine, but there is no guarantee that those native packages are available in the Function environment.

You should look for alternative packages that achieve similar results without native dependencies for a consistent experience. [bcryptjs](https://github.com/dcodeIO/bcrypt.js) is an example of a pure JavaScript implementation that works across different environments without any native dependencies.

> **Note:** You may be able to install the necessary shared libraries in the [Build Image](https://vercel.com/docs/concepts/deployments/troubleshoot-a-build#build-image) prior to running `npm install`

## Reading from the filesystem

On your local machine, you have access to a persistent filesystem that you can read from and write to. This is not the case for Vercel Functions. Learn more about [reading files in Vercel Functions](https://vercel.com/guides/how-can-i-use-files-in-serverless-functions).

## Environment variables

If you have any [environment variables](https://vercel.com/docs/concepts/projects/environment-variables) defined in your local environment that your Vercel Functions depend on, you'll need to make sure they are defined the same way in your [Preview](https://vercel.com/docs/platform/deployments#preview), and [Production](https://vercel.com/docs/platform/deployments#production) environments. The [Environment Variables UI](https://vercel.com/docs/concepts/projects/environment-variables) provides an easy way to do so.

## Logs

Logging is essential to debugging your software. Place log statements in key areas of your code to better understand what's going on. Make sure to install a [Log Drain Integration](https://vercel.com/integrations?category=logging#logging) for your deployed functions so you can have persistent debugging information available when needed. Consult your logs to see if there are any differences across environments.

## Community support

If you're still stuck after considering all of the above and need a fresh pair of eyes on your problem, consider [starting a discussion](https://community.vercel.com) to get help from our Vercel Community. When starting discussions requesting help, please provide detailed steps on how to reproduce the issue you're running into along with the solutions you've tried so far.

## Related Documentation

- [Vercel Functions](/docs/functions)

## More Vercel Functions guides

- [Optimize Runtime Cache on Vercel](/kb/guide/optimize-runtime-cache-reads-on-vercel): Diagnose rising Runtime Cache usage, trace reads to tags and code paths, and reduce avoidable reads while checking write cost and origin traffic.
- [How to stop Vercel Functions from timing out](/kb/guide/what-can-i-do-about-vercel-serverless-functions-timing-out): Vercel Functions that time out usually trace back to a few causes. Learn how Fluid Compute fixes most of them and how to handle the edge cases.
- [The Complete Guide to Vercel Connect](/kb/guide/vercel-connect): Use Vercel Connect to call provider APIs like Slack, GitHub, Linear, Microsoft, Discord, Snowflake, and Salesforce from your agents and services with short-lived, scoped tokens instead of long-lived secrets.

## Reference Architecture

Choose a stack and work through the decisions behind it, with curated documentation, guides, templates, and courses to help you build.

- [Agent stack](/kb/architecture/agents): Build and operate agents with models, tools, and durable workflows.
- [Web applications](/kb/architecture/web): Choose rendering, data, authentication, and caching approaches.
- [Backends](/kb/architecture/backends): Choose a runtime, connect services, and run background work.

[Browse all stacks](/kb/architecture)

## Build with prompts

Build an app, extend an agent, or improve your project with ready-to-use prompts for your coding agent.

[Browse the prompt library](/kb/prompts) · [Read the Markdown index](/kb/prompts.md)
