mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
errors: don't throw TypeError on missing export
Logic in module_job.js assumes detailed stack trace from node_errors.cc which is not populated when --enable-source-maps is set. Fixes #38790 PR-URL: https://github.com/nodejs/node/pull/39017 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
This commit is contained in:
1 parent
b9866098a7
commit
663d7e9fb2
7 files changed
+35
-1
No files matched your search
@@ -24,6 +24,9 @@ const {
|
||||
const { ModuleWrap } = internalBinding('module_wrap');
|
||||
|
||||
const { decorateErrorStack } = require('internal/util');
|
||||
const {
|
||||
getSourceMapsEnabled,
|
||||
} = require('internal/source_map/source_map_cache');
|
||||
const assert = require('internal/assert');
|
||||
const resolvedPromise = PromiseResolve();
|
||||
|
||||
@@ -122,7 +125,12 @@ class ModuleJob {
|
||||
}
|
||||
} catch (e) {
|
||||
decorateErrorStack(e);
|
||||
if (StringPrototypeIncludes(e.message,
|
||||
// TODO(@bcoe): Add source map support to exception that occurs as result
|
||||
// of missing named export. This is currently not possible because
|
||||
// stack trace originates in module_job, not the file itself. A hidden
|
||||
// symbol with filename could be set in node_errors.cc to facilitate this.
|
||||
if (!getSourceMapsEnabled() &&
|
||||
StringPrototypeIncludes(e.message,
|
||||
' does not provide an export named')) {
|
||||
const splitStack = StringPrototypeSplit(e.stack, '\n');
|
||||
const parentFileUrl = StringPrototypeReplace(
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"esm-export-missing-module.esm","sourceRoot":"","sources":["./exm-export-missing-module.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;AAEzB,CAAC"}
|
||||
@@ -0,0 +1,2 @@
|
||||
import { Something } from './esm-export-missing-module.mjs';
|
||||
//# sourceMappingURL=esm-export-missing.mjs.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"esm-export-missing.ts","sourceRoot":"","sources":["./esm-export-missing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC"}
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
import { Something } from './exm-export-missing-module.mjs';
|
||||
console.info(Something);
|
||||
@@ -324,6 +324,25 @@ function nextdir() {
|
||||
assert.ok(sourceMap);
|
||||
}
|
||||
|
||||
// Does not throw TypeError when exception occurs as result of missing named
|
||||
// export.
|
||||
{
|
||||
const coverageDirectory = nextdir();
|
||||
const output = spawnSync(process.execPath, [
|
||||
'--enable-source-maps',
|
||||
require.resolve('../fixtures/source-map/esm-export-missing.mjs'),
|
||||
], { env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
|
||||
const sourceMap = getSourceMapFromCache(
|
||||
'esm-export-missing.mjs',
|
||||
coverageDirectory
|
||||
);
|
||||
// Module loader error displayed.
|
||||
assert.match(output.stderr.toString(),
|
||||
/does not provide an export named 'Something'/);
|
||||
// Source map should have been serialized.
|
||||
assert.ok(sourceMap);
|
||||
}
|
||||
|
||||
function getSourceMapFromCache(fixtureFile, coverageDirectory) {
|
||||
const jsonFiles = fs.readdirSync(coverageDirectory);
|
||||
for (const jsonFile of jsonFiles) {
|
||||
|
||||
Reference in new issue
Block a user