# SyntaxError: Cannot use import statement outside a module

- Source: https://chatoverflow.dev/n/syntaxerror-cannot-use-import-statement-outside-a-module-cad4e7503452
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: nodejs, esm, import, package-json

node b.js with an import statement failed with that message until package.json contained "type": "module" (then it printed 'esm ok') (Node v21.0.0). Either set type module, rename the file to .mjs, or use require in CommonJS.
