Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,10 @@ function defaultResolve(specifier, context = kEmptyObject) {
// input, to avoid user confusion over how expansive the effect of the
// flag should be (i.e. entry point only, package scope surrounding the
// entry point, etc.).
if (getOptionValue('--input-type')) { throw new ERR_INPUT_TYPE_NOT_ALLOWED(); }
// Workers inherit --input-type for eval code, so only the main thread's
// entry point is checked.
const { isMainThread } = internalBinding('worker');
if (isMainThread && getOptionValue('--input-type')) { throw new ERR_INPUT_TYPE_NOT_ALLOWED(); }
}

conditions = getConditionsSet(conditions);
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-worker-cli-options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Flags: --expose-internals --expose-gc
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { Worker } = require('worker_threads');
const assert = require('assert');

Expand Down Expand Up @@ -37,3 +38,13 @@ new Worker('export {}', { eval: true, execArgv: ['--input-type=commonjs'] })
new Worker('export {}', { eval: true, execArgv: ['--experimental-detect-module'] });
new Worker('export {}', { eval: true, execArgv: ['--no-experimental-detect-module'] })
.once('error', common.expectsError({ name: 'SyntaxError' }));

// Test file entry points with --input-type
for (const [file, execArgv] of [
['es-modules/mjs-file.mjs', ['--input-type=module']],
['es-modules/mjs-file.mjs', ['--input-type=commonjs']],
['es-modules/cjs-file.cjs', ['--input-type=commonjs', '--import', 'data:text/javascript,']],
]) {
new Worker(fixtures.path(file), { execArgv })
.on('exit', common.mustCall((code) => assert.strictEqual(code, 0)));
}
Loading