dnt — the easiest way to publish a hybrid npm module for ESM and CommonJS
dnt (Deno to Node transform) is a build tool that turns a Deno/TypeScript module into an npm package shipping ESM, CommonJS and TypeScript declarations. It rewrites module specifiers, injects shims for Deno APIs, maps remote imports to npm dependencies, type checks with tsc, and runs the test suite in both CJS and ESM under Node. A worked example builds and publishes a small module via a build_npm.ts script, then automates releases with a GitHub Actions workflow that publishes to npm on tagged releases.
Related posts
- How to publish Deno modules to NPM
Deno mediumAdeptThe oak HTTP middleware framework was ported from Deno to npm using dnt, a build pipeline that rewrites module specifiers, injects shims for Deno and web globals, type checks with tsc, emits ESM/CommonJS plus type declarations, and runs Deno.test suites under Node.js. Porting required shimming web streams, Web Crypto, Blob, fetch/Headers via undici, and a custom ErrorEvent. It also meant removing top-level await so CommonJS output works, and using dnt's mapping feature to swap in a Node.js "http" server abstraction (about 220 lines versus 160 for Deno). Remaining rough edges include differing custom-inspect symbols, undici Headers behaviour around Set-Cookie, and a few platform-branched tests.
- Deno 1.34: deno compile supports npm packages
Deno mediumAdeptDeno 1.34 lets `deno compile` bundle npm packages and their dependencies into a single self-contained executable. That makes tools like vite and eslint shippable as binaries with pinned dependencies, and they tend to start faster than running from a local cache. The release also adds cross-platform glob support in deno.json, deno task and CLI flags, and TLS certificates with IP addresses via rustls. Smaller changes include a top-level `exclude` and `nodeModulesDir` in config, configurable language-server limits, a `Deno.serve()` signature change that returns a `Deno.Server`, new `createHttpClient` pool options, more Node.js polyfills, and upgrades to V8 11.5 and TypeScript 5.0.4.
- If you're not using npm specifiers, you're doing it wrong
Deno mediumAdeptDeno now recommends importing npm packages with native `npm:` specifiers instead of HTTP transpile services like esm.sh or unpkg. Those services lack semver-aware deduplication, so duplicate copies of React can load, and they can't run install hooks for native add-ons or serve bundled data files. Native `npm:` imports resolve versions properly and need no node_modules or package.json, since packages go to a global cache. They also work in Jupyter and the REPL, fall under Deno's permission model with opt-in `--allow-scripts`, and support private registries via `.npmrc`.
- Self-contained Executable Programs with Deno Compile
Deno mediumAdept`deno compile` turns JavaScript and TypeScript programs into standalone binaries for Windows, macOS and Linux that run without Deno installed. It works by bundling the module graph into an eszip file and injecting it with Sui into a slimmed-down runtime binary, denort. Because the bundle sits in a section of the executable, the result can still be code signed. Examples cover cross-compiling with `--target`, custom icons, preserved permission flags, and compiling npm itself, which ran about 1.9x faster on `npm -v`. Assets can be embedded as base64-encoded modules until native asset bundling arrives.
- Deno 2.3: Improved deno compile, local npm packages, and more
Deno mediumAdeptDeno 2.3 lets deno compile bundle programs that use FFI and Node native add-ons, adds --include/--exclude control over embedded files, and exposes Deno.build.standalone to detect compiled binaries. Local npm packages can now be used through a "patch" entry in deno.json. deno fmt gains formatting of CSS, HTML and SQL in tagged templates plus 14 new options, and OpenTelemetry support adds span events, cross-service context propagation, node:http auto-instrumentation and V8 heap metrics. deno install is about 2x faster when npm dependencies are cached, thanks to in-memory npm metadata caching and lockfile v5, with a benchmark showing 2.5x on a Vite React template. The release also adds the JavaScript `using` keyword, coverage ignore comments and TypeScript 5.8 with V8 13.5.