Repository navigation
eve/next throws ERR_INVALID_ARG_VALUE when imported under node -e (trusts the global __filename, which is "[eval]") #4646
Description
Link to a minimal reproduction
No repository needed; it reproduces in an empty folder:
npm init -y
npm install eve@0.76.3
node -e "import('eve/next').then(() => console.log('loaded ok'), e => console.log(e.code, '-', e.message))"Steps to reproduce
- Install eve in any project.
- Import
eve/nextfrom a script that Node runs with-e/--eval(eitherrequire('eve/next')with--input-type=commonjsor a dynamicimport('eve/next')).
Current vs. expected behavior
Current: the import throws.
ERR_INVALID_ARG_VALUE - The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '[eval]'
Stack, from a real project (eve 0.70.1, loaded through Next's next.config.ts require hook):
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '[eval]'
at createRequire (node:internal/modules/cjs/loader:2081:13)
at file:///…/node_modules/eve/dist/src/internal/application/package.js:1:1201
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:543:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:343:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1690:24)
…
at require.extensions..js (…/node_modules/next/dist/build/next-config-ts/require-hook.js:49:20)
Expected: the import succeeds, as it does when the same line is in a file (node probe.cjs prints loaded ok), and as import('eve') does under -e.
Cause: packages/eve/src/internal/application/package.ts
function resolveCurrentModulePath(): string {
if (typeof __filename === "string") {
return __filename;
}
return resolveCurrentModulePathFromStack();
}
…
const packageRequire = createRequire(resolveCurrentModulePath());The module is ESM, so it has no module-local __filename; the bare identifier resolves to the global scope. Under node -e, Node defines globalThis.__filename = "[eval]" (node -e "console.log(globalThis.__filename)" prints [eval]), so the check passes and createRequire("[eval]") throws. Anything else that defines a global __filename would mislead it the same way.
eve version
0.76.3 (latest at the time of writing; reproduced with the commands above). Also 0.70.1, where it was first seen.
Environment
- Node.js 24.19.0
- Windows 11 (x64)
- npm
Where does the bug occur?
Local development.
Build and runtime logs
See the error and stack above. No other output.
Prompt or implementation plan for our agents (optional)
In packages/eve/src/internal/application/package.ts, do not take the module path from a global. Either use import.meta.url (createRequire(import.meta.url)), or accept __filename only when path.isAbsolute(__filename) and fall back to resolveCurrentModulePathFromStack() otherwise. Validate with: node -e "import('eve/next').then(() => console.log('loaded ok'))" printing loaded ok.
Additional context
How this surfaced: vercel dev (CLI 62.1.0, @vercel/next 16.0.0; still the case in @vercel/next 22.0.1) loads the app's next.config.* in a child started with node --input-type=commonjs -e <loader> to build its dev manifest. With withEve imported at the top of next.config.ts, that child exits 1 and vercel dev never starts listening. So every Next app that uses withEve and is run through vercel dev is affected.
Workaround in the app: export an async config function from next.config.ts, and inside it delete globalThis.__filename when it equals "[eval]", await import('eve/next'), then restore the global.
Activity
test(eve): reproduce eve/next failing to load under node -e
roboeve commentedon Oct 11, 2026
Confirmed on
origin/main: importingeve/nextfrom anode -escript throwsERR_INVALID_ARG_VALUE, becausepackage.tsreads Node's global__filename("[eval]") and passes it tocreateRequire. The same import from a file, or with--input-type=module -e, loads fine.Repro: #4647
Regressed in: not a recent regression. The check dates back to #1, and every release checked from
eve@0.70.1toeve@0.76.3fails.fix(eve): ignore non-path global __filename when resolving the packag…
roboeve commentedon Oct 11, 2026
Fix proposed in #4648, assigned to @ruiconti. This issue closes when it merges.