canirequire

canirequireCommonJS › array.prototype.flat

Is array.prototype.flat ESM-only? Can you require() it?

An ES2019 spec-compliant `Array.prototype.flat` shim/polyfill/replacement that works as far down as ES3.

Last verified Sep 9, 2026 against array.prototype.flat@1.3.3. JSON

CommonJS CommonJS — require() works on every Node.js version

array.prototype.flat ships CommonJS only. require("array.prototype.flat") works everywhere. import "array.prototype.flat" 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.

Latest
1.3.3 (Dec 15, 2024)
Module format
CommonJS
Last CommonJS version
1.3.3
TypeScript types
@types/array.prototype.flat
Node engines
>= 0.4
Weekly downloads
49.6M
License
MIT

Does array.prototype.flat@1.3.3 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("array.prototype.flat") from a CommonJS file and import "array.prototype.flat" from an ES module.

Runtimerequire("array.prototype.flat")import "array.prototype.flat"
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✓ works✓ works

How to import array.prototype.flat

ES modules (import)

import arrayPrototypeFlat from "array.prototype.flat";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const arrayPrototypeFlat = require("array.prototype.flat");

Module format by version

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

VersionsFormatFirst published
1.2.1 – 1.3.3CommonJSMay 22, 2018

Frequently asked

Is array.prototype.flat ESM-only?

array.prototype.flat@1.3.3 is a CommonJS package. array.prototype.flat ships CommonJS only. require("array.prototype.flat") works everywhere. import "array.prototype.flat" 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 array.prototype.flat with ES module syntax?

Yes. import arrayPrototypeFlat from "array.prototype.flat" 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 array.prototype.flat work in Bun?

Yes. import "array.prototype.flat" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does array.prototype.flat ship TypeScript types?

Not bundled. Install the community types with "npm install -D @types/array.prototype.flat".

Links

Other commonjs packages

Similar popularity