---
title: "dnt — the easiest way to publish a hybrid npm module for ESM and CommonJS"
description: "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."
url: "https://swe.quest/articles/dnt-the-easiest-way-to-publish-a-hybrid-npm-module-for-esm-and-commonjs-3ee76ec474a313e6"
canonical: "https://deno.com/blog/publish-esm-cjs-module-dnt"
source: "Deno"
published: "2023-07-31"
difficulty: "medium"
kind: "How-to"
reading_minutes: 5
tags: ["typescript","javascript","build-systems","ci-cd"]
---

# dnt — the easiest way to publish a hybrid npm module for ESM and CommonJS

A post on [Deno](https://swe.quest/sources/deno.md), published 2023-07-31, 5 min read, How-to. Original: [https://deno.com/blog/publish-esm-cjs-module-dnt](https://deno.com/blog/publish-esm-cjs-module-dnt)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Build systems](https://swe.quest/tags/build-systems.md) (Engineering practices)
- [CI/CD](https://swe.quest/tags/ci-cd.md) (Reliability & operations)

## Prerequisites

- ESM vs CommonJS modules
- npm publishing
- Deno basics

## Keywords

dnt, Deno, Node.js, npm, CommonJS, ESM, GitHub Actions

## Related posts

- [How to publish Deno modules to NPM](https://swe.quest/articles/how-to-publish-deno-modules-to-npm-bc17082adc782014.md): Deno · 2022-02-28 · Medium · 8 min read · JavaScript, TypeScript, Build systems, Open source
  The 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.
- [Deno 1.34: deno compile supports npm packages](https://swe.quest/articles/deno-1-34-deno-compile-supports-npm-packages-6066648b7bf9ee04.md): Deno · 2023-05-25 · Medium · 6 min read · JavaScript, Runtimes & VMs, Developer tools, TypeScript
  Deno 1.34 lets \`deno compile\` bundle npm packages and their dependencies into a single self-contained executable.
- [If you're not using npm specifiers, you're doing it wrong](https://swe.quest/articles/if-you-re-not-using-npm-specifiers-you-re-doing-it-wrong-1ef0f76947ddfda3.md): Deno · 2025-02-13 · Medium · 7 min read · JavaScript, TypeScript, Build systems, Supply chain security
  Deno now recommends importing npm packages with native \`npm:\` specifiers instead of HTTP transpile services like esm.sh or unpkg.
- [Self-contained Executable Programs with Deno Compile](https://swe.quest/articles/self-contained-executable-programs-with-deno-compile-1f904f454f37c8a8.md): Deno · 2024-11-14 · Medium · 5 min read · JavaScript, TypeScript, Build systems, Developer tools
  \`deno compile\` turns JavaScript and TypeScript programs into standalone binaries for Windows, macOS and Linux that run without Deno installed.
- [Deno 2.3: Improved deno compile, local npm packages, and more](https://swe.quest/articles/deno-2-3-improved-deno-compile-local-npm-packages-and-more-8da91030a8445369.md): Deno · 2025-05-01 · Medium · 11 min read · JavaScript, TypeScript, Runtimes & VMs, Developer tools, Observability
  Deno 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
