package type field

The "type" setting in package.json that makes Node.js treat the package's .js files as ES modules ("module") or CommonJS ("commonjs").

In more detail

When it is missing, Node.js looks at the syntax to guess, but setting it explicitly avoids surprises. Files ending in .mjs are always ES modules and .cjs always CommonJS, whatever the field says.

Related terms

Taught in

References