[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"howto:cjs:linux:en":3},{"resolvedFromAlias":4,"canonicalExt":5,"ext":5,"name":6,"category":7,"categoryName":8,"updatedAt":9,"os":10,"osLabel":11,"quickSolution":12,"stepByStep":13,"recommendedSoftware":16,"alternativeMethods":17,"commonIssues":18,"securityNote":37,"extensionPath":38,"extensionLabel":39,"breadcrumbs":40,"metaDescription":50},false,"cjs","CommonJS Module File","code","Code","2026-06-12T08:01:45.984Z","linux","Linux","To open .CJS files on Linux, open the .cjs file in a code editor (it is plain text JavaScript).",[14,15],"Open the .cjs file in a code editor (it is plain text JavaScript).","To run it, open a terminal, cd to the folder, and run: node yourfile.cjs",[],[],[19,25,31],{"title":20,"description":21,"steps":22},"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.",[23,24],"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.",{"title":26,"description":27,"steps":28},"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.",[29,30],"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.",{"title":32,"description":33,"steps":34},"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.",[35,36],"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).",".cjs files contain executable JavaScript; running an untrusted .cjs file with Node.js can execute arbitrary code with your user permissions.","/file-extension/cjs",".CJS",[41,44,47],{"label":42,"to":43},"Home","/",{"label":45,"to":46},"How To","/file-extension",{"label":48,"to":49},"Open .CJS on Linux","/how-to/open-cjs-on-linux","Learn how to open .CJS files on Linux with step-by-step instructions, recommended software, and troubleshooting tips."]