.CJS file extension

To open .CJS files on Windows, open the .cjs file in a code editor (it is plain text JavaScript).

To open a .cjs file, use a code editor (it’s plain-text JavaScript) or run it with Node.js. In Node.js, the .cjs extension guarantees the file is treated as CommonJS, even if the surrounding package is configured for ES modules.

Last updated: June 12, 2026

Open on your device

Choose your operating system for a dedicated step-by-step opening guide.

How to open .CJS files

Use these platform-specific instructions to open .CJS files safely.

Windows

  1. Open the .cjs file in a code editor (it is plain text JavaScript).
  2. To run it, open PowerShell or Command Prompt, go to the file’s folder, and run: node yourfile.cjs
Full Windows guide

Mac

  1. Open the .cjs file in a code editor (it is plain text JavaScript).
  2. To run it, open Terminal, cd to the folder, and run: node yourfile.cjs
Full Mac guide

Linux

  1. Open the .cjs file in a code editor (it is plain text JavaScript).
  2. To run it, open a terminal, cd to the folder, and run: node yourfile.cjs
Full Linux guide

iOS

  1. If you only need to read it, open it in a plain-text/code viewer; to execute it you’ll typically need to transfer it to a desktop/server with Node.js.
Full iOS guide

Android

  1. If you only need to read it, open it in a plain-text/code viewer; to execute it you’ll typically need to transfer it to a desktop/server with Node.js.
Full Android guide

Security notes

  • .cjs files contain executable JavaScript; running an untrusted .cjs file with Node.js can execute arbitrary code with your user permissions.
  • The .cjs extension forces CommonJS interpretation in Node.js; if you expected ESM behavior (or assumed import/export constraints), that mismatch can lead to unintended execution paths when code is reused across projects.
  • When serving JavaScript over the web, the relevant standards-based media type is text/javascript; do not rely on the file extension alone for safe content handling or correct interpretation.

Before you run downloaded code

These files usually need a runtime (Python, Node, Java, …). They are not classic “file viruses,” but untrusted code can still do serious harm if you execute it. Prefer official packages, verify publishers, and scan archives or sketchy downloads when you are unsure.

We may earn a commission when you use affiliate links. This supports our free file extension guides.

Can't open this file?

These are the most common causes and fixes when .CJS files fail to open.

Common reasons

  • Node.js runs it as CommonJS when you expected ESM
  • Syntax error: using import/export in a .cjs file
  • A tool expects .js and does not recognize .cjs

Fix steps

  1. If you want ESM semantics (import/export), rename the file to .mjs or .js (and ensure your package configuration matches).
  2. If you need CommonJS, keep .cjs and use require/module.exports rather than import/export.

What is a .CJS file?

.cjs is not a separate “binary” format; it’s JavaScript source code saved with an extension that signals Node.js module interpretation. Per Node.js package/module rules, files ending in .cjs are always treated as CommonJS modules regardless of the nearest parent package.json. This is especially useful when a package sets "type": "module" (making .js default to ESM) but still needs some CommonJS files.

Background

The .cjs extension is part of Node.js’s approach to handling the coexistence of CommonJS (require/module.exports) and ECMAScript modules (import/export). In Node.js, a project’s package.json can influence whether .js files are interpreted as ESM or CommonJS, but .cjs is an explicit override that always means CommonJS.

Common MIME types: text/javascript

Further reading

Authoritative resources for more details on the .CJS format.

Common .CJS 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.

  1. If you want ESM semantics (import/export), rename the file to .mjs or .js (and ensure your package configuration matches).
  2. 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.

  1. Replace import/export with require() and module.exports/exports for CommonJS.
  2. 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.

  1. Check the tool’s configuration for an option to specify the entry file explicitly and point it to the .cjs path.
  2. If the tool cannot be configured, consider keeping a small .js wrapper that loads the .cjs module (or renaming if compatible).

FAQ

What is the difference between .cjs and .js in Node.js?

In Node.js, .cjs is always treated as a CommonJS module regardless of the nearest parent package.json. By contrast, .js can be treated as CommonJS or ESM depending on package configuration (for example, "type": "module").

When should I use .cjs?

Use .cjs when you need a specific file to be CommonJS (require/module.exports) even inside a codebase or package that otherwise uses ESM defaults (for example, when "type": "module" makes .js behave as ESM).

Is there an official MIME type for .cjs?

There is no widely standardized, extension-specific media type for .cjs in the IANA registry. For JavaScript/ECMAScript content, standards guidance centers on text/javascript.

Can TypeScript output .cjs files?

TypeScript documentation notes that Node.js treats .cjs output as CommonJS, and TypeScript uses that behavior when reasoning about Node.js module formats and emitted outputs.

Similar file extensions

Compare related formats in the same category to find the right tool faster.