Skip to content

sea: support ESM entry point in SEA - #61813

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
joyeecheung:sea-esm
Feb 18, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
joyeecheung:sea-esm

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Feb 13, 2026 •

Copy link
Copy Markdown
Member

This uses the new StartExecutionCallbackWithModule embedder API added in #61548 to support ESM entrypoint in SEA via a new configuration field "mainFormat". The behavior currently aligns with the embedder API and is mostly in sync with the CommonJS entry point behavior, except that support for code caching and snapshot is left for follow-ups.

Similar to CommonJS entrypoints, non-builtin access is currently not supported - though the WIP VFS would unlock that. This PR would allow users that are bundling their apps for SEA building to target ESM instead of CommonJS for the bundle output.

Build with: node --build-sea sea-config.json

{
  "main": "sea.mjs",
  "output": "sea",
  "mainFormat": "module",
}
// sea.mjs
// Static import for builtins is supported.
import assert from 'node:assert';
import { pathToFileURL } from 'node:url';

// Dynamic import() for builtins and top-level await are supported
const { strict } = await import('node:assert');
assert.strictEqual(strict, assert.strict);

// import.meta is supported (mostly)
assert.strictEqual(import.meta.url, pathToFileURL(process.execPath).href);
assert.strictEqual(import.meta.filename, process.execPath);
assert.strictEqual(import.meta.dirname, dirname(process.execPath));
assert.strictEqual(import.meta.main, true);

// import.meta.resolve is currently unsupported - will depend on something like VFS.

Note: for follow-ups:

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/single-executable