AI with AIlabs
← All guides
3 min read

Every serverless function on my portfolio failed to load and the build said it was fine

A missing .js extension, a contact form that returned 500, and why I moved my Messages relay from Twilio to Slack.


Build LogClaude CodeVercelSlackVite

Learn · Nov 6, 2026

I spent the day on my portfolio. It's a desktop-style site with popup case studies, a Mail window, a Messages window, and a dock at the bottom.

The Mail form is the part visitors actually use. So when /api/send-email returned a 500 in production, I stopped everything else.

Here's the thing: the build was green. Vercel said READY. The site loaded. Only the functions behind it were dead.

This is the kind of bug that makes you feel foolish for about ten minutes and then teaches you something permanent. I'm writing it down so the ten minutes are shorter for you.

Read the error, not the build status

A green deploy only tells you the files got uploaded. It doesn't tell you the functions can start. I checked the runtime side instead, and every serverless function was failing at load with ERR_MODULE_NOT_FOUND. Not one function. All of them. That pattern matters. When everything fails the same way, the cause usually lives in how the project is set up, not in any single file. A deploy is a build result. A working route is a request result. They're two different checks, and only the second one matters to a visitor.

Find what the whole project has in common

My package.json has "type": "module". That tells Node to treat every file as an ES module. And Node's ES module resolver is strict: relative imports need an explicit file extension. My api/ files imported each other without one. Something like a bare relative path to a helper. That works in a bundler. It doesn't work when Node loads the file directly. So the function died before it could run a single line. Bundlers tend to forgive a missing extension. Node's own loader doesn't. Same code, different loader, different rules.

Fix it in one pass and ship it alone

The fix was boring. I added .js extensions to every relative import under api/, then pushed that as its own commit. Nothing else rode along with it. That was on purpose. If the next deploy broke something, I wanted exactly one change to blame. The deploy went READY, and the send-email route stopped returning 500. After the deploy, the check that counts is a real request to the route. One real submission tells you more than any status page.

Rebuild the Messages relay around Slack

The same day, I changed how the Messages window works. It started on Twilio. I moved it to Slack. Now a visitor's message posts into a Slack channel, one thread per visitor. When I reply in that thread, a signed Slack Events webhook at /api/slack-events delivers my reply back into the visitor's Messages popup. I get to answer from the app I already have open. Why move at all? A text-message relay needs a phone number and a carrier. Slack needs a channel I'm already reading. Fewer moving parts means fewer places for a request to go wrong, and replies land where I'll actually see them. I'm not claiming Slack is better for everyone. It's better for how I work.

Harden the relay before you trust it

A relay that takes outside input and forwards it is an attack surface. Before the switch, I ran a hardening pass on the Twilio version. The Twilio webhook now requires a PUBLIC_BASE_URL and fails closed, instead of checking the signature against a URL built from the Host header. It records each MessageSid so a replayed request gets rejected. And it compares the owner's full normalized phone number instead of a partial match. The common thread is simple. Fail closed. If a setting is missing, refuse the request. Don't guess. The Slack side follows the same rule. The Events webhook is signed, so a request that can't prove it came from Slack gets nothing.

What broke: Every serverless function in the portfolio failed at load with ERR_MODULE_NOT_FOUND, so /api/send-email returned 500 in production. The cause: package.json set "type": "module", and Node's ESM resolver needs explicit extensions on relative imports. My api/ files had none. The build still showed READY because the static site was fine.

The fix: I added .js extensions to every relative import under api/ and deployed that change by itself. Then I checked the route again in production instead of trusting the green build. For the Messages relay, I moved it to a Slack thread per visitor with a signed webhook, and kept the fail-closed checks from the hardening pass. Next, I'll run the audit prompt below on every new project the day I add an api/ folder, so this one gets caught before a visitor finds it.

Audit serverless functions for ESM import errors
Review every file under api/ in this repo.

1. Check package.json for "type": "module".
2. List every relative import (starting with ./ or ../) that has no file extension.
3. For each one, tell me the exact file and line, and the corrected import with the right extension (.js for compiled TypeScript output).
4. Don't change anything yet. Show me the list first.
5. After I approve, apply the fixes in one commit with a message that names the cause.
6. Then tell me how to confirm in production that each function loads, using the runtime logs and a real request to each route, not just the deploy status.

Get new guides and builds in your inbox

No noise. New artifacts, skills, and lessons when they drop — and early access when agents launch.

next_steps.exe

Want a full structured path instead of one-off guides?

That's Learn AI with AI — a sequenced course that takes you from zero to building real things, with community and accountability built in.

Check out Learn AI with AI →