How to open .CJS files on Windows
To open .CJS files on Windows, open the .cjs file in a code editor (it is plain text JavaScript).
Step-by-step instructions
- Open the .cjs file in a code editor (it is plain text JavaScript).
- To run it, open PowerShell or Command Prompt, go to the file’s folder, and run: node yourfile.cjs
Common issues
Node.js runs it as CommonJS when you expected ESM
In Node.js, .cjs is always CommonJS, even if your package.json sets "type": "module" and your other .js files behave as ESM.
- If you want ESM semantics (import/export), rename the file to .mjs or .js (and ensure your package configuration matches).
- If you need CommonJS, keep .cjs and use require/module.exports rather than import/export.
Syntax error: using import/export in a .cjs file
Because .cjs is forced to CommonJS in Node.js, ESM-only syntax can fail depending on how it is executed and what syntax is used.
- Replace import/export with require() and module.exports/exports for CommonJS.
- If the file must use ESM, switch to .mjs (or adjust your package setup so .js is ESM) and update imports accordingly.
A tool expects .js and does not recognize .cjs
Some workflows and scripts are hard-coded to look for .js and won’t pick up .cjs automatically.
- Check the tool’s configuration for an option to specify the entry file explicitly and point it to the .cjs path.
- If the tool cannot be configured, consider keeping a small .js wrapper that loads the .cjs module (or renaming if compatible).
Security note
.cjs files contain executable JavaScript; running an untrusted .cjs file with Node.js can execute arbitrary code with your user permissions.