# Is unique-filename ESM-only? Can you require() it?

> unique-filename@6.0.0 is a CommonJS package. CommonJS — require() works on every Node.js version we test.

Generate a unique filename for use in temporary directories or caches.

Last verified Sep 9, 2026 against unique-filename@6.0.0.

unique-filename ships CommonJS only. require("unique-filename") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js ^22.22.2 || ^24.15.0 || >=26.0.0. import "unique-filename" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

## What to do

1. require("unique-filename") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js ^22.22.2 || ^24.15.0 || >=26.0.0.
2. From ES modules use the default import: import uniqueFilename from "unique-filename"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: no types are available for unique-filename; declare the module yourself if you need them.

## Facts

- Latest: 6.0.0 (May 15, 2026)
- Module format: CommonJS
- Last CommonJS version: 6.0.0
- TypeScript types: none
- Node engines: ^22.22.2 || ^24.15.0 || >=26.0.0
- Weekly downloads: 24.6M
- License: ISC

## Runtime test results for unique-filename@6.0.0

Installed and executed on Sep 9, 2026 with require("unique-filename") from a CommonJS file and import "unique-filename" from an ES module.

| Runtime | require("unique-filename") | import "unique-filename" |
|---|---|---|
| Node.js 18 | works | works |
| Node.js 20 | works | works |
| Node.js 22 | works | works |
| Node.js 24 | works | works |
| Node.js 26 | works | works |
| Bun 1.4.0 | works | works |

## How to import unique-filename

ES modules:

```js
import uniqueFilename from "unique-filename";
```

CommonJS:

```js
const uniqueFilename = require("unique-filename");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (9 versions; the newest 9 shown).

| Versions | Format | First published |
|---|---|---|
| 1.0.0 – 6.0.0 | CommonJS | May 7, 2015 |

## Frequently asked

**Is unique-filename ESM-only?**

unique-filename@6.0.0 is a CommonJS package. unique-filename ships CommonJS only. require("unique-filename") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js ^22.22.2 || ^24.15.0 || >=26.0.0. import "unique-filename" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

**Can I import unique-filename with ES module syntax?**

Yes. import uniqueFilename from "unique-filename" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

**Does unique-filename work in Bun?**

Yes. import "unique-filename" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does unique-filename ship TypeScript types?**

No. unique-filename ships no type declarations and there is no @types package for it.

## Links

- [unique-filename on npm](https://www.npmjs.com/package/unique-filename)
- [Source repository](https://github.com/npm/unique-filename)
- [HTML version](https://canirequire.com/package/unique-filename/)
- [JSON version](https://canirequire.com/package/unique-filename.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
