Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: fix initial ModuleWrap with non-string source #33443

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ translators.set('module', async function moduleStrategy(url) {
source, { url, format: 'module' }, defaultTransformSource));
maybeCacheSourceMap(url, source);
debug(`Translating StandardModule ${url}`);
const module = new ModuleWrap(url, undefined, source, 0, 0);
const module = new ModuleWrap(url, undefined, `${source}`, 0, 0);
moduleWrap.callbackMap.set(module, {
initializeImportMeta,
importModuleDynamically,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function transformSource() {
return {
source: {
boom: true
}
};
}
4 changes: 4 additions & 0 deletions test/message/esm-invalid-transform-source.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-invalid-transform-source.mjs
// Fixes: https://github.com/nodejs/node/issues/33441
import '../common/index.mjs';
import 'fs';
9 changes: 9 additions & 0 deletions test/message/esm-invalid-transform-source.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///*/test/message/esm-invalid-transform-source.mjs:1
[object Object]
^^^^^^

SyntaxError: Unexpected identifier
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
at async link (internal/modules/esm/module_job.js:*:*)