fix: ESM world loading for @workflow/world-postgres #836
fix: ESM world loading for @workflow/world-postgres #836michael-han-dev wants to merge 7 commits into
Conversation
Signed-off-by: voyager14 <21mh124@queensu.ca>
Signed-off-by: voyager14 <21mh124@queensu.ca>
🦋 Changeset detectedLatest commit: 9f49cee The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@michael-han-dev is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Resolved conflicts: - packages/core/src/runtime/world.ts: Updated createVercelWorldFromEnv() to use main's new API (removed baseUrl and skipProxy) - packages/cli/src/lib/inspect/setup.ts: Kept initWorld import for external ESM world support
65002aa to
2a8033e
Compare
Use require.resolve() from process.cwd() to resolve bare module specifiers before importing. This fixes ERR_MODULE_NOT_FOUND in CI where the dynamic import was resolving from packages/core context instead of the app's node_modules. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: voyager14 <21mh124@queensu.ca>
Signed-off-by: voyager14 <21mh124@queensu.ca>
bc85dd8 to
eb5d013
Compare
Signed-off-by: voyager14 <21mh124@queensu.ca>
|
Hi @michael-han-dev, we're currently discussing changes to the |
|
#942 refactors |
|
Yeah #942 might be the right approach but also still needs discussion. we def. don't want to add yet another world instantiation function |
Description
@workflow/world-postgres fails with ERR_REQUIRE_ESM because world.ts used require() to load external worlds, but postgres is ESM-only. fixmade : replace require() with dynamic import() via new Function() to bypass bundler static analysis. Added initWorld() for async world loading. External worlds now need await initWorld() instead of getWorld() - though this was already broken before, so nothing that was working is changing. Built-in worlds (local, vercel) unchanged. updated docs accordingly as well. fixes #812
How did you test your changes?
Added packages/core/src/runtime/world.test.ts with 13 tests
Postgres World Testing
Ran a local postgres container (
postgres:18-alpine) on port 5432.Framework Tests
Built and started each framework with
WORKFLOW_TARGET_WORLD=@workflow/world-postgresand the postgres connection string. All four logged "Starting Postgres World..." and started without ESM errors.node .output/server/index.mjs, server on localhost:3000node .output/server/index.mjs, server on localhost:3000node build/index.js, server on localhost:3000The Astro
start-with-pg.mjsscript fails withERR_MODULE_NOT_FOUND. Pre-existing issue unrelated to this PR. Bundled output works.Edge Cases
Tested invalid module path (throws
ERR_MODULE_NOT_FOUND), module with wrong exports (throws "Invalid target world module"), external world accessed before init (throws "Call await initWorld() first"), and built-in worlds (still work synchronously).E2E with Postgres
Pushed the database schema via
pnpm db:pushin world-postgres. Started Next.js Turbopack with postgres world env vars. Triggered the simple workflow via curl to/api/trigger. Got back a run ID.Verified in postgres: workflow run created, step created, pg-boss jobs queued and processed. The ESM module loaded correctly and the World instance worked.
Also ran the same workflow with local world to confirm end-to-end execution works. It does.
PR Checklist - Required to merge
pnpm changesetwas run to create a changelog for this PRpnpm changeset --emptyif you are changing documentation or workbench appsgit commit --signoffon your commits)