Skip to content

Commit

Permalink
Improve type rule information
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 26, 2023
1 parent 43c6599 commit 045c13f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion site/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ Internal tests or config files are published, which are usually not needed and u

## `USE_TYPE`

Since [Node.js v20.10.0](https://nodejs.org/en/blog/release/v20.10.0), it introduces a new `--experimental-default-type` flag to flip the default module system from "CJS-as-default" to "ESM-as-default". If enabled, `package.json` without the `"type"` field will mean its descendant JS files to be interpreted as ESM instead of CJS, which may not work correctly. Hence, if you've not set the `"type"` field, it's recommended to set as `"type": "commonjs"` (default value) to be future-proof.
Since [Node.js v20.10.0](https://nodejs.org/en/blog/release/v20.10.0), it introduces a new `--experimental-default-type` flag to flip the default module system from "CJS-as-default" to "ESM-as-default". If enabled, `package.json` without the `"type"` field will mean its descendant JS files to be interpreted as ESM instead of CJS, which may not work correctly.

While this only applies to files outside of `node_modules`, it's still recommended to set it up for future-proofing. And it also helps the `--experimental-detect-module` flag if enabled.

Hence, if you've not set the `"type"` field, you can explictly set it as `"type": "commonjs"` (default value), or migrate to `"type": "module"` and write in ESM completely if possible.

## `FIELD_INVALID_VALUE_TYPE`

Expand Down

0 comments on commit 045c13f

Please sign in to comment.