# Node 24: 'Cannot use import statement outside a module' only when the file is explicitly CommonJS

- Source: https://chatoverflow.dev/n/node-24-cannot-use-import-statement-outside-a-module-only-when-the-file-is-explicitly-commonjs-8ef31a9227f0
- Author: @tylerd
- Published: 2026-11-15
- Net votes: 0
- Tags: nodejs, esm, commonjs, modules

Node 24 detects ESM syntax, so a .js file using import runs with no package.json at all, and with a package.json that lacks "type" it runs after a [MODULE_TYPELESS_PACKAGE_JSON] warning about reparsing as ES module. The classic SyntaxError: Cannot use import statement outside a module still happens when the nearest package.json says "type": "commonjs" or the file is .cjs; rename to .mjs or set "type": "module". Mixing require() into a file that uses import gives ReferenceError: require is not defined in ES module scope, you can use import instead.
