The Vercel functions dev initial experience isn't great

See Vercel CLI local development server does not work with TypeScript API functions · vercel · Discussion #5539 · GitHub (the problem that I currently have).

It’s easier to set up a NextJS project to set up API routes than to use the native building blocks of vercel functions. There isn’t a template for simple vercel functions usage in vercel init. I couldn’t find information about es module support or how to build the code (TS) to be correctly supported on the runtime. And it’ts hard to find information because it’s mixed with NextJS stuff :face_with_spiral_eyes:

Hey @benjavicente. Someone else had a similar problem with TS functions recently, but with a Hono project. The solution was to set the tsconfig.json for ESM and make sure it’s not excluded by .vercelignore. Can you give this a try and let me know if it works for you?

In case it helps, I put together a small example repo showing how a Vercel Function can be used with just the Node.js runtime.

Repo: GitHub - amyegan/bare-bones-func: A demonstration of Vercel Functions without a framework
Example: bare-bones-func.vercel.app
Steps I followed:

  1. Create a new repo with npm init and git init
  2. Run npm install vercel --save-dev to include the CLI as a dev dependency
  3. Add a tsconfig.json with module: ESNext and moduleResolution: node as compilerOptions
  4. Add /api/index.ts with export function GET() and return your desired response. (I copied the Other Frameworks example from the Vercel Functions Quickstart page)
  5. Include a vercel.json file to redirect from the home path to /api
  6. Run the project locally with vercel dev :tada:
1 Like