Fix · Node, npm and build
"Cannot use import statement outside a module" or ERR_REQUIRE_ESM
What you may see
- A script fails on the first import line
- A package says it is an ES module
Most likely cause
Node has two module styles (import and require) and the file or package uses the one that does not match the settings.
Check first (about two minutes)
- Does your package.json have "type": "module"? Is the file .js, .mjs or .cjs?
The fix prompt
What you type here never leaves your browser. The search runs on this page, and nothing is sent to a server or to an AI.
Kept only in this browser, on this device. Keys and passwords are removed before anything is saved.
Prompt language
Paste it into Claude, ChatGPT, Gemini or Cursor, then follow what it says.
After you tried it, did it work?
Steps
- Show the top of the failing file, package.json type, and how the script is started.
- Choose ONE style for the project and make the file match: rename to .mjs, or set "type", or use dynamic import() for a package that is ES-only.
Do not do this
- Do not mix require and import in the same file.
- Do not convert all files at once.