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
When wrapping an import with try/catch, and when pointing the import to a TS file that does not exist, the error caught should have code = ERR_MODULE_NOT_FOUND.
err.code is undefined in ESM context, but defined in CommonJS context, when caught in the importing script.
Steps to reproduce the problem
ESM
// error.mjs, call with `ts-node ./error.mjs`
try {
await import('./test.ts') // Does not exist
} catch (err) {
console.log(err.stack) // Has the proper message & stack (Cannot find module...)
// Undefined, should be ERR_MODULE_NOT_FOUND
// Note that if you run the same code with `node` instead, code is defined.
console.log(err.code)
}
CommonJS
// error.cjs, call with `ts-node ./error.cjs`
try {
require('./test.ts') // Does not exist
} catch (err) {
console.log(err.stack) // Has the proper message & stack (Cannot find module...)
console.log(err.code) // MODULE_NOT_FOUND
}
Search Terms
code
. Found this but not sure if related.Expected Behavior
When wrapping an import with try/catch, and when pointing the import to a TS file that does not exist, the error caught should have
code = ERR_MODULE_NOT_FOUND
.ts-node seems to properly throw this error here:
ts-node/raw/node-internal-modules-esm-resolve-v15.3.0.js
Lines 258 to 259 in 8b09d49
Actual Behavior
err.code
is undefined in ESM context, but defined in CommonJS context, when caught in the importing script.Steps to reproduce the problem
ESM
CommonJS
Specifications
The text was updated successfully, but these errors were encountered: