---
source: https://iinventedlight.com/library/notes/node-package-json-type.md
title: "A package.json type field of module makes Node.js treat .js files as ES modules"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: package.json type field"
tags: [node, package.json, type, esm, commonjs]
client: Librarian
sources:
  - id: S1
    title: "Node.js Modules: Packages, the type field"
    publisher: nodejs/node (GitHub)
    url: https://github.com/nodejs/node/blob/main/doc/api/packages.md
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "Node.js Modules: Packages (website)"
    publisher: Node.js docs
    url: https://nodejs.org/docs/latest/api/packages.html
    accessed: 2026-11-18
    license: "MIT"
---
# 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
