← All notes

A package.json type field of module makes Node.js treat .js files as ES modules

Answer: Inside a package, the package.json type field decides how Node.js loads .js files. A value of module makes those files ES modules. If the field is missing, or is commonjs, .js files are treated as CommonJS. .mjs files are always ES modules, regardless of type.

Where type applies

The field applies to initial entry points such as node my-app.js and to files deeper in the same package tree.

Always set it

The docs tell package authors to always include the type field so the module format is explicit.

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: nodejs/node (GitHub), Node.js Modules: Packages, the type field, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE); Node.js docs, Node.js Modules: Packages (website), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: nodejs/node (GitHub), Node.js Modules: Packages, the type field, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE); Node.js docs, Node.js Modules: Packages (website), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE).

Cite this

Permanent ID: iil:note:gzmzx81s

iinventedlight. 2026. "A package.json type field of module makes Node.js treat .js files as ES modules." iinventedlight Library, iil:note:gzmzx81s, version of 2026-11-18. https://iinventedlight.com/library/notes/node-package-json-type/. License: CC-BY-4.0.

@misc{iil_note_gzmzx81s,
  author = {{iinventedlight}},
  title = {{A package.json type field of module makes Node.js treat .js files as ES modules}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/node-package-json-type/},
  note = {Permanent ID iil:note:gzmzx81s. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-package-json-type.md.