Skip to content

Commit b1f08b8

Browse files
guybedfordtargos
authored andcommitted
module: no type module resolver side effects
PR-URL: #33086 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
1 parent 13cae34 commit b1f08b8

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

doc/api/esm.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,6 @@ The resolver can throw the following errors:
16051605
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
16061606
> _mainExport_, _""_).
16071607
> 1. Throw a _Package Path Not Exported_ error.
1608-
> 1. If _pjson.main_ is a String, then
1609-
> 1. Let _resolvedMain_ be the URL resolution of _packageURL_, "/", and
1610-
> _pjson.main_.
1611-
> 1. If the file at _resolvedMain_ exists, then
1612-
> 1. Return _resolvedMain_.
1613-
> 1. If _pjson.type_ is equal to _"module"_, then
1614-
> 1. Throw a _Module Not Found_ error.
16151608
> 1. Let _legacyMainURL_ be the result applying the legacy
16161609
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
16171610
> _Module Not Found_ error for no resolution.

lib/internal/modules/esm/resolve.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
439439

440440
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(packageJSONUrl, '.');
441441
}
442-
if (packageConfig.main !== undefined) {
443-
const resolved = new URL(packageConfig.main, packageJSONUrl);
444-
const path = fileURLToPath(resolved);
445-
if (tryStatSync(path).isFile()) return resolved;
446-
}
447442
if (getOptionValue('--experimental-specifier-resolution') === 'node') {
448443
if (packageConfig.main !== undefined) {
449444
return finalizeResolution(
@@ -453,9 +448,7 @@ function packageMainResolve(packageJSONUrl, packageConfig, base, conditions) {
453448
new URL('index', packageJSONUrl), base);
454449
}
455450
}
456-
if (packageConfig.type !== 'module') {
457-
return legacyMainResolve(packageJSONUrl, packageConfig);
458-
}
451+
return legacyMainResolve(packageJSONUrl, packageConfig);
459452
}
460453

461454
throw new ERR_MODULE_NOT_FOUND(

test/es-module/test-esm-type-main.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { mustNotCall } from '../common/index.mjs';
2+
import assert from 'assert';
3+
import { importFixture } from '../fixtures/pkgexports.mjs';
4+
5+
(async () => {
6+
const m = await importFixture('type-main');
7+
assert.strictEqual(m.default, 'asdf');
8+
})()
9+
.catch(mustNotCall);

test/fixtures/node_modules/type-main/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/type-main/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)