You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Confusing error message when a non-Error value is thrown during require() #35687
The problem can be reproduced with these three files:
// index.mjs import'./cjs-file.cjs'
// cjs-file.cjs require('./throws')
// throws.js throw'string'
Run this with node --experimental-modules index.mjs.
What is the expected behavior?
I expected to see something like this, which is what I see when I run node cjs-file.cjs:
throws.js:1
throw 'string'
^
string
(Use `node --trace-uncaught ...` to show where the exception was thrown)
What do you see instead?
I see this:
$ node --experimental-modules index.mjs
internal/per_context/primordials.js:23
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
^
TypeError: String.prototype.split called on null or undefined
at split (<anonymous>)
at internal/per_context/primordials.js:23:32
at enrichCJSError (internal/modules/esm/translators.js:139:17)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:182:9)
at ModuleJob.run (internal/modules/esm/module_job.js:146:23)
at async Loader.import (internal/modules/esm/loader.js:165:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5)
This error message is a) super confusing and b) masks the original error.
Additional information
It looks to me like the enrichCJSError function either shouldn't be assuming that the error is an object with a stack property, or the caller should be checking for something like instanceof Error first.
Activity
module: only try to enrich CJS syntax errors
module: only try to enrich CJS syntax errors
module: only try to enrich CJS syntax errors
module: only try to enrich CJS syntax errors
module: only try to enrich CJS syntax errors
module: only try to enrich CJS syntax errors