Node "Warning: To load an ES module, set type: module" in CI
Node started parsing a .js file as CommonJS, hit ESM syntax, and printed a performance warning before reparsing it as a module. Declaring the module type removes the warning and the double parse.
What this error means
Output includes "(node:NNN) Warning: To load an ES module, set \"type\": \"module\" in the package.json or use the .mjs extension" followed by a "reparsing as ES module" note.
(node:21456) Warning: To load an ES module, set "type": "module" in the package.json or
use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)Common causes
ESM syntax in a .js file with no declared type
Without "type", Node defaults to CommonJS, fails to parse, and falls back to reparsing as ESM with a warning.
A workflow that treats warnings as errors
CI configured to fail on stderr or with --throw-deprecation-style strictness turns the warning into a job failure.
How to fix it
Declare the module type
Set "type": "module" so Node parses the file as ESM the first time with no warning.
{
"type": "module"
}Or use an explicit extension
Rename ESM entry files to .mjs so Node never guesses the module format.
node ./bin/cli.mjsHow to prevent it
- Always declare
"type"inpackage.jsonfor clarity and speed. - Use
.mjs/.cjsfor files that must be one specific format. - Do not rely on the reparse fallback in production scripts.