How to open .CJS files on Android

To open .CJS files on Android, 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.

Step-by-step instructions

  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.

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.

  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).

Security note

.cjs files contain executable JavaScript; running an untrusted .cjs file with Node.js can execute arbitrary code with your user permissions.

Back to .CJS extension page