Skip to content

FE-1631: Fix Node ESM imports in Petrinaut Vercel Functions - #9589

Merged
kostandinang merged 2 commits into
mainfrom
kostandin/fe-1631-fix-node-esm-imports-in-petrinaut-vercel-functions
Sep 9, 2026
Merged

FE-1631: Fix Node ESM imports in Petrinaut Vercel Functions#9589
kostandinang merged 2 commits into
mainfrom
kostandin/fe-1631-fix-node-esm-imports-in-petrinaut-vercel-functions

Conversation

@kostandinang

@kostandinang kostandinang commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🌟 What is the purpose of this PR?

Petrinaut's Voice and oEmbed Vercel Functions currently fail before their handlers run because the emitted ESM retains extensionless relative imports. Native Node ESM resolution does not append .js, so Vercel reports ERR_MODULE_NOT_FOUND and the Voice config endpoint returns 500.

This repairs the complete local runtime import graphs and adds a dedicated NodeNext TypeScript project that recursively checks every Petrinaut Vercel Function entrypoint using native Node ESM resolution rules.

🔗 Related links

🚫 Blocked by

  • Nothing

🔍 What does this change?

  • Adds .js to relative imports used by the oEmbed, Voice config, and Voice Realtime call runtime graphs.
  • Adds api/tsconfig.json with NodeNext resolution and verbatimModuleSyntax, recursively covering current and future Vercel Function entrypoints.
  • Runs both the browser and API TypeScript projects from lint:tsc, while limiting ambient Node types to the API project.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph

⚠️ Known issues

This restores function loading only. Petrinaut's current policy still disables OpenAI Voice in production; enabling production Voice requires the separate authentication/security work tracked by FE-1622.

🐾 Next steps

  • Smoke-test /api/voice/config, /api/voice/realtime-call, and /api/oembed on the Vercel preview.

🛡 What tests cover this?

  • Dedicated NodeNext TypeScript checking for all Vercel Function entrypoints and their imported local modules.
  • Existing Voice config, Voice Realtime call, and oEmbed endpoint unit tests.
  • Complete @apps/petrinaut-website unit-test suite.
  • Dependency-aware production build, TypeScript checks, and Oxlint.

❓ How to test this?

  1. Run mise exec -- turbo run build --filter='@apps/petrinaut-website'.
  2. Run mise exec -- yarn workspace @apps/petrinaut-website test:unit.
  3. Run mise exec -- yarn workspace @apps/petrinaut-website lint:tsc.
  4. On the Vercel preview, confirm Voice config returns JSON, an invalid Realtime request returns a controlled 4xx, and a valid oEmbed request returns JSON rather than FUNCTION_INVOCATION_FAILED.

📹 Demo

Not applicable: this fixes serverless module loading and has no visual change.

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
petrinaut Ready Ready Preview Sep 8, 2026 8:44pm UTC
petrinaut-docs Ready Ready Preview Sep 8, 2026 8:44pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
hash Ignored Ignored Preview Sep 8, 2026 8:44pm UTC
hashdotdesign-tokens Ignored Ignored Preview Sep 8, 2026 8:44pm UTC

Request Review

@cursor

cursor Bot commented Sep 8, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Import-path and TypeScript project-boundary changes only; no handler logic changes, but incorrect paths would still break production API routes.

Overview
Fixes Vercel function boot failures (ERR_MODULE_NOT_FOUND) by making relative imports in the oEmbed and Voice API graphs use explicit .js extensions, which Node 22 ESM requires at runtime.

Adds a dedicated api/tsconfig.json (NodeNext / verbatimModuleSyntax) and runs a second tsgo pass in lint:tsc, while the main app tsconfig no longer includes api/ and sets types: [] so browser and Node typing stay separated. @types/node is added for API-side typechecking.

Reviewed by Cursor Bugbot for commit 7addf29. Bugbot is set up for automated code reviews on this repo. Configure here.

@kostandinang

Copy link
Copy Markdown
Contributor Author

Preview smoke test passed on the Petrinaut deployment:

  • GET /api/voice/config200 with {"available":true,"connectionTimeoutMs":15000}
  • GET /api/voice/realtime-call → controlled 405 with Allow: POST, request ID, and server timing
  • Valid GET /api/oembed200 with the expected JSON payload

None of the routes produced FUNCTION_INVOCATION_FAILED or ERR_MODULE_NOT_FOUND.

@kube kube left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for discovering that.

Please check my comment on adding another tsconfig.json rather than creating unit tests to verify compilation.

Comment thread apps/petrinaut-website/src/server/vercel-function-entrypoints.test.ts Outdated
Comment thread apps/petrinaut-website/package.json
Co-authored-by: Cursor <cursoragent@cursor.com>

@kube kube left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
This will also solve the oEmbed issue I had to investigate. (certainly)

Comment thread apps/petrinaut-website/tsconfig.json
@kostandinang
kostandinang added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit ef0f444 Sep 9, 2026
55 checks passed
@kostandinang
kostandinang deleted the kostandin/fe-1631-fix-node-esm-imports-in-petrinaut-vercel-functions branch September 9, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps area/deps Relates to third-party dependencies (area)

Development

Successfully merging this pull request may close these issues.

2 participants