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
- id: C1 claim: A type value of module makes Node.js interpret .js files as ES modules. source: S1 evidence: "A
package.json\"type\"value of\"module\"tells Node.js to interpret.js"
- id: C2 claim: Without type, or with type commonjs, .js files are CommonJS. source: S1 evidence: "files are treated as [CommonJS]"
- id: C3 claim: The published packages page documents the type field. source: S2 evidence: "\"type\""
- id: C4 claim: The published page also describes the module value. source: S2 evidence: "\"module\""
Sources
- [S1] Node.js Modules: Packages, the type field. nodejs/node (GitHub). https://github.com/nodejs/node/blob/main/doc/api/packages.md . License: MIT. Accessed 2026-11-18.
- [S2] Node.js Modules: Packages (website). Node.js docs. https://nodejs.org/docs/latest/api/packages.html . License: MIT. Accessed 2026-11-18.
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
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.},
}
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.