Skip to content

Make the compiled package loadable as native ESM - #260

Open
gronke wants to merge 1 commit into
espressif:mainfrom
gronke:fix/native-esm-imports
Open

Make the compiled package loadable as native ESM#260
gronke wants to merge 1 commit into
espressif:mainfrom
gronke:fix/native-esm-imports

Conversation

@gronke

@gronke gronke commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Serving lib/ to a browser without a bundler fails on the first module. Two independent causes, both in the sources, since TypeScript rewrites no specifiers.

Relative specifiers carry no extension. A browser resolves ./webserial as a URL and requests a file that does not exist, so the module graph never finishes loading. Every relative specifier now ends in .js, which the compiler emits verbatim and every bundler already understands.

Interfaces are re-exported as values. export { SerialOptions } from "./webserial.js" emits a runtime re-export of a binding the compiled module does not have, and the browser throws on load. Each type-only re-export is now export type, which emits nothing. ESPLoader, Transport, ROM and the reset classes stay value exports.

The stub JSON, the other half, needs import attributes and so a newer TypeScript, which is a separate change.

…re-exports

A browser resolves a relative specifier as a URL, so `./webserial` requests a file that does not exist and the module graph fails to load.
TypeScript rewrites no specifiers, so the extension belongs in the source.

An interface re-exported with `export { … }` emits a runtime re-export of a binding the compiled module does not have, which throws on load; `export type` emits nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant