From 2c3338871c095eab30fd08bf5b7f9b7a09932535 Mon Sep 17 00:00:00 2001 From: Taron Sung Date: Thu, 29 Jan 2026 21:22:27 +0900 Subject: [PATCH] docs: add ESM import documentation Add documentation for importing debug using ESM syntax with the import statement. Includes examples for both JavaScript and TypeScript usage. Fixes #1019 --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 9ebdfbf1..d87db7a1 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,37 @@ workb(); The `DEBUG` environment variable is then used to enable these based on space or comma-delimited names. +### ESM (ECMAScript Modules) + +When using ESM with `import` syntax, you can import `debug` as follows: + +```js +import debug from 'debug'; + +const log = debug('app:log'); + +log('booting %o', 'My App'); +``` + +If you want to use a different variable name for the factory function: + +```js +import debug from 'debug'; + +const createDebug = debug; +const log = createDebug('app:log'); +``` + +For TypeScript users, the same import syntax works: + +```ts +import debug from 'debug'; + +const log = debug('http'); + +log('request received'); +``` + Here are some examples: screen shot 2017-08-08 at 12 53 04 pm