[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"extension:v3:en:cjs":3},{"resolvedFromAlias":4,"canonicalExt":5,"ext":5,"name":6,"category":7,"categoryName":8,"updatedAt":9,"popularity":10,"summary":11,"howToOs":12,"quickAnswer":18,"answerIntro":19,"whatIs":20,"description":21,"furtherReading":22,"openInstructions":38,"commonIssues":49,"securityNotes":68,"faq":72,"aliases":85,"mimeTypes":86,"relatedExtensions":88,"breadcrumbs":136,"categoryAnchor":146,"categoryFuturePath":147,"metaDescription":148,"availableHowToOs":149,"openOnDeviceLinks":150,"cannotOpenReasons":166,"cannotOpenFixes":167,"convertOptions":168,"securityAffiliateMessaging":169,"securityAffiliates":170},false,"cjs","CommonJS Module File","code","Code","2026-06-12T08:01:45.984Z",55,".cjs is a JavaScript source file that Node.js always interprets as a CommonJS module. It’s commonly used in projects that otherwise default to ES modules, to force a specific file to use CommonJS semantics.",[13,14,15,16,17],"windows","mac","linux","ios","android","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.",".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.","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.",[23,26,29,32,35],{"title":24,"url":25},"Node.js v17.4.0 Documentation — Packages (module rules for .cjs)","https://nodejs.org/download/release/v17.4.0/docs/api/packages.html",{"title":27,"url":28},"Node.js package examples — CommonJS and ESM (why/when to use .cjs)","https://nodejs.github.io/package-examples/01-getting-started/commonjs-and-esm.html",{"title":30,"url":31},"TypeScript Handbook — Modules (theory; notes on Node treating .cjs as CommonJS)","https://www.typescriptlang.org/docs/handbook/modules/theory.html",{"title":33,"url":34},"IANA Media Types Registry (to verify official registrations)","https://www.iana.org/assignments/media-types/media-types.xhtml",{"title":36,"url":37},"Shared MIME-info Database specification (how desktop systems map extensions to MIME types)","https://specifications.freedesktop.org/shared-mime-info-spec/latest-single/",{"windows":39,"macos":42,"linux":44,"ios":46,"android":48},[40,41],"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",[40,43],"To run it, open Terminal, cd to the folder, and run: node yourfile.cjs",[40,45],"To run it, open a terminal, cd to the folder, and run: node yourfile.cjs",[47],"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.",[47],[50,56,62],{"title":51,"description":52,"steps":53},"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.",[54,55],"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":57,"description":58,"steps":59},"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.",[60,61],"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":63,"description":64,"steps":65},"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.",[66,67],"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).",[69,70,71],".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.",[73,76,79,82],{"question":74,"answer":75},"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\").",{"question":77,"answer":78},"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).",{"question":80,"answer":81},"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.",{"question":83,"answer":84},"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.",[],[87],"text/javascript",[89,95,100,106,112,118,124,130],{"ext":90,"name":91,"category":7,"categoryName":8,"popularity":92,"summary":93,"howToOs":94},"php","PHP script (PHP source code)",85,".php files typically contain PHP source code used on web servers to generate dynamic web pages and API responses. You can open them in a code editor, but they are usually executed by a web server (often via PHP-FPM) rather than “run” like a normal desktop app.",[13,14,15,16,17],{"ext":96,"name":97,"category":7,"categoryName":8,"popularity":92,"summary":98,"howToOs":99},"sql","SQL script (Structured Query Language)",".sql files contain SQL statements (queries, schema definitions, and data changes) that can be run by a database tool or opened as plain text for review and editing.",[13,14,15,16,17],{"ext":101,"name":102,"category":7,"categoryName":8,"popularity":103,"summary":104,"howToOs":105},"cs","C# source code file",80,".cs files contain C# source code used to build .NET applications and libraries. They are plain-text files typically edited in code editors and IDEs such as Visual Studio Code with C# tooling.",[13,14,15,16,17],{"ext":107,"name":108,"category":7,"categoryName":8,"popularity":109,"summary":110,"howToOs":111},"go","Go source file",78,".go files contain source code written in the Go (Golang) programming language. You can open them in code editors (for reading/editing) or build/run them with the Go toolchain.",[13,14,15,16,17],{"ext":113,"name":114,"category":7,"categoryName":8,"popularity":115,"summary":116,"howToOs":117},"tsx","TypeScript JSX (TSX) source file",75,".tsx is a TypeScript source code file that contains JSX syntax, commonly used with React-style UI components. You open it in a code editor (for viewing/editing) and build it with TypeScript tooling (for running in apps).",[13,14,15,16,17],{"ext":119,"name":120,"category":7,"categoryName":8,"popularity":121,"summary":122,"howToOs":123},"kt","Kotlin source file",72,".kt files contain Kotlin source code used to build Kotlin applications (including Android apps) and libraries. You typically open them in a code editor or IDE such as IntelliJ IDEA or Android Studio.",[13,14,15,16,17],{"ext":125,"name":126,"category":7,"categoryName":8,"popularity":127,"summary":128,"howToOs":129},"swift","Swift Source Code",70,".swift is a Swift programming language source file used to write apps and other software. You open it in code editors and IDEs such as Xcode or other text/code editors.",[13,14,15,16,17],{"ext":131,"name":132,"category":7,"categoryName":8,"popularity":133,"summary":134,"howToOs":135},"dart","Dart source code",65,".dart files contain source code written in the Dart programming language. You open them in a code editor/IDE or work with them using the Dart SDK tools.",[13,14,15,16,17],[137,140,143],{"label":138,"to":139},"Home","/",{"label":141,"to":142},"File Extension Index","/file-extension",{"label":144,"to":145},".CJS","/file-extension/cjs","category-code","/category/code","Learn what .CJS files are, how to open them on every platform, common fixes, and security best practices.",[13,14,15,16,17],[151,154,157,160,163],{"os":13,"label":152,"to":153},"Open .CJS on Windows","/how-to/open-cjs-on-windows",{"os":14,"label":155,"to":156},"Open .CJS on Mac","/how-to/open-cjs-on-mac",{"os":15,"label":158,"to":159},"Open .CJS on Linux","/how-to/open-cjs-on-linux",{"os":16,"label":161,"to":162},"Open .CJS on iOS","/how-to/open-cjs-on-ios",{"os":17,"label":164,"to":165},"Open .CJS on Android","/how-to/open-cjs-on-android",[51,57,63],[54,55],[],"code_runtime",[171,175],{"name":172,"description":173,"affiliateUrl":174},"Avast","Avast offers free and premium antivirus software that protects against viruses, malware, ransomware, and phishing. Scan files before opening them to ensure safety.","https://www.avast.com/lp-aff-consumer-store?expid=inf601",{"name":176,"description":177,"affiliateUrl":178},"Norton","Norton 360 delivers comprehensive antivirus protection, VPN, and identity theft monitoring. Scan files for threats before opening to keep your device secure.","http://buy.norton.com/aff_home?utm_campaign=en-ww_nor_n36_aff_nas_nau_nah_cj_nad_low:_sec_nat_mktc_norton_360"]