Ffile2fix
Sign in Get started

What is a .js file?

A .js file contains JavaScript source code, the language that runs in web browsers and on servers through Node.js, Deno and Bun. Websites load .js files for interactivity, and build tools, config files and npm packages are also written in it.

Key facts

  • Plain UTF-8 text; MIME type is text/javascript (RFC 9239), replacing the older application/javascript.
  • Can be a classic script or an ES module using import/export; Node decides by the nearest package.json "type" field, and .mjs and .cjs force each mode.
  • Production builds are usually bundled and minified as .min.js, often with a .map source map file alongside.
  • On Windows, double-clicking a .js file runs it with Windows Script Host rather than opening it, which malware abuses.
  • Created by developers and generated by bundlers such as Vite, webpack, esbuild and the TypeScript compiler.

How to open a .js file

Windows

Right-click and choose Open with > VS Code or Notepad++ to view it; do not double-click unknown .js files. Run trusted scripts with node script.js after installing Node.js.

macOS

Open it in VS Code or any code editor, and run it in Terminal with node script.js (install Node.js from nodejs.org or Homebrew).

Linux

View it with less script.js or a code editor, and run it with node script.js after installing Node.js from your distribution or NodeSource.

Common problems and fixes

"SyntaxError: Cannot use import statement outside a module"
The file uses ES module syntax but is loaded as a classic script. Add "type": "module" to package.json, rename it to .mjs, or load it with <script type="module"> in the browser.
"Uncaught SyntaxError: Unexpected token '<'"
The browser requested a .js file but received an HTML page, usually a 404 or SPA fallback. Open the script URL directly and fix its path or the server's routing.
"ReferenceError: require is not defined"
CommonJS require() is used in an ES module or in the browser. Switch to import syntax, rename the file to .cjs for Node, or bundle it for the browser.
Minified code is impossible to read or debug
Use the browser DevTools {} pretty-print button or a formatter for a readable copy. Load the matching source map to see original file names and lines.
Windows warns or antivirus flags a downloaded .js file
Script files attached to emails or downloads are a common malware vector that runs via Windows Script Host. Do not run it; inspect it in a text editor or delete it.

Often converted to or from: TypeScript, minified JS, MJS / CJS, JSON (data only)

Frequently asked questions

How do I run a .js file?

Install Node.js and run node script.js in a terminal. Browser scripts are loaded by an HTML page with a <script src="script.js"></script> tag.

Is a .js file a virus?

Most .js files are normal website or app code, but a .js file received by email or download can run on Windows when double-clicked. Never run JavaScript files from untrusted sources.

What is the difference between .js, .mjs and .cjs?

.mjs is always treated as an ES module and .cjs always as CommonJS. A plain .js file follows the "type" setting in the nearest package.json, defaulting to CommonJS in Node.

See all file types β†’ Β· Browse error fixes β†’