Explain ES module require errors
Paste a Node.js "require is not defined in ES module scope" error, and Vibe explains it in plain English: why Node.js treated the file as an ES module, and what changes if you switch to import or rename the file.
Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.
Vibe13 lines selected
Press Explain it for the sample, or paste your own code first.
What this require in ES modules sample shows
- the message
- The
^sits underrequireon line 1, and the topatline says the same withcount-notes.js:1:12.requireis how CommonJS files load other code, and an ES module has norequire, so the first line failed and nothing else ran; the run ended with exit code 1.node:fsitself is there, built into Node.js: what's missing is the function that would load it. - why it's an ES module
- The next line gives the reason: the file ends in
.jsand/home/dev/notes/package.jsoncontains"type": "module". That one line in package.json makes Node.js load the.jsfiles under it as ES modules; a file ending in.mjsis one wherever it is.npm run countprinted the same error after its> node count-notes.jsline. - import instead
- With lines 1 and 2 changed to
import fs from 'node:fs';andimport path from 'node:path';, line 1 worked and line 4 failed:ReferenceError: __dirname is not defined in ES module scope.__dirnameis CommonJS too. Withimport.meta.dirnamein its place, the script printed3 notes, 2 donewith exit code 0. - .cjs instead
- Renaming the file to count-notes.cjs, with the
requirelines kept, also printed3 notes, 2 done, as the error suggests. Butnpm run countstill rannode count-notes.jsfrom package.json and failed withError: Cannot find module '/home/dev/notes/count-notes.js'. A rename needs every place that names the file changed too.
Good to know
- Run with Node.js 25.7.0 and npm 11.10.1 on Linux in a test folder mounted at /home/dev/notes, which is why the paths start with
/home/dev/notes. On your computer they show where your own file is. - Node.js stops at the first error in a file. The import change fixed line 1 and only then showed the
__dirnameproblem on line 4, so run the script again after each fix.
Before you trust it: Deleting "type": "module" from package.json also made count-notes.js run, but it changes the other files too. list-notes.js, which uses import, still ran but first printed a MODULE_TYPELESS_PACKAGE_JSON warning asking for "type": "module" back in package.json. When an AI tool fixes this error by editing package.json, run the other scripts in the folder as well.
Explain ES module require errors beside your editor
Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).
Install on Mac
curl -fsSL https://unvibe.site/install.sh | bashPaste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.
Or download the .dmg · Intel Mac build · SHA-256 checksums
No install warning? Use Unvibe in your browser
Opening the .dmg the first time
Unvibe isn't notarized by Apple yet, so macOS blocks the first open until you allow it. Its code is public on GitHub.
- Open the .dmg, drag Unvibe to Applications and open it. macOS says it can't verify it. Click Done, not the blue Move to Trash.

Real screen, macOS 26. On macOS 15 the two buttons sit side by side. - System Settings › Privacy & Security, scroll down to Security, then press Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.

Real screen, macOS 15 - Unvibe opens. You only do this once, and later versions install from inside the app with one click.

Real screen, Unvibe 0.1.51 on macOS 26
The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open