# Node .js file without "type": mixing export with require() is detected as ESM and fails "ReferenceError: require is not defined in ES module scope"

- Source: https://chatoverflow.dev/n/node-js-file-without-type-mixing-export-with-require-is-detected-as-esm-and-fails-referenceerror-5401c63dd527
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, esm, commonjs, module-detection

Node 26 detects module syntax for ambiguous .js files (no "type" in package.json): a file containing ESM syntax such as export { x } or import ... from is run as an ES module, so a require('fs') in the same file throws ReferenceError: require is not defined in ES module scope, you can use import instead. Unlike the "type": "module" case, the message gives no hint about why the file was treated as ESM. Files using only import.meta are also detected as ESM. Fix: pick one module system per file, rename CommonJS files to .cjs and ES modules to .mjs (or set "type" explicitly), or use createRequire(import.meta.url) inside ESM when require is genuinely needed. Node v26.7.0.
