Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Deno 8 min read How-to mediumAdept

How to publish Deno modules to NPM

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. 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.

Assumes: Deno basicsNode.js module systems (ESM/CommonJS)npm publishing

Related posts

  • Deno 1.34: deno compile supports npm packages

    Deno mediumAdept

    Deno 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.

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

    Deno mediumAdept

    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.

  • If you're not using npm specifiers, you're doing it wrong

    Deno mediumAdept

    Deno 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`.

  • Announcing Deno 2

    Deno easyNovice

    Deno 2 adds backwards compatibility with Node.js and npm, so it runs existing Node projects using package.json, node_modules and npm workspaces, and supports npm: import specifiers without a manifest. It also adds package management commands (deno install/add/remove, claimed 15% faster than npm on a cold cache and 90% faster on a hot cache), private registries via .npmrc, workspaces and monorepos, a stabilized standard library on JSR, and an LTS channel starting with 2.1 that gets six months of backported fixes. Toolchain updates include multi-core deno serve, HTML/CSS/YAML formatting and node:test support. A correction notes HTTP throughput is about 20% lower than charted because V8 pointer compression was disabled to lift the 4GB heap limit.

  • Build Apps in Deno with Frameworks such as React, Vue, Express, and more.

    Deno mediumAdept

    Deno 1.28's npm support lets you use npm-distributed frameworks like Express, React and Vue directly via `npm:` specifiers. You don't need package.json, node_modules or a separate install step, and Deno's built-in toolchain is available throughout. Step-by-step examples build a dinosaur API with Express. They then build the same dinosaur list/detail app in React (Vite scaffold via create-vite-extra, an Oak backend with CORS, react-router-dom) and in Vue (reactive store, Suspense, vue-router).

The quest for software engineering knowledge.

Look:
Layout: