diff --git a/doc/api/esm.md b/doc/api/esm.md index ee71cf61d4..05d01f7390 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -268,6 +268,8 @@ import feature from 'es-module-package/features/x.js'; If a package has no exports, setting `"exports": false` can be used instead of `"exports": {}` to indicate the package does not intent for submodules to be exposed. +This is just a convention that works because `false`, just like `{}`, has no +iterable own properties. ## import Specifiers diff --git a/src/module_wrap.cc b/src/module_wrap.cc index b7c0e8bdcf..0574f896df 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -615,8 +615,7 @@ Maybe GetPackageConfig(Environment* env, Persistent exports; if (pkg_json->Get(env->context(), env->exports_string()).ToLocal(&exports_v) && - (exports_v->IsObject() || - (exports_v->IsBoolean() && exports_v->IsFalse()))) { + !exports_v->IsNullOrUndefined()) { exports.Reset(env->isolate(), exports_v); auto entry = env->package_json_cache.emplace(path, diff --git a/test/es-module/test-esm-exports.mjs b/test/es-module/test-esm-exports.mjs index 45f1518dfd..fc3c07d8bc 100644 --- a/test/es-module/test-esm-exports.mjs +++ b/test/es-module/test-esm-exports.mjs @@ -4,7 +4,7 @@ import { mustCall } from '../common/index.mjs'; import { ok, strictEqual } from 'assert'; import { asdf, asdf2 } from '../fixtures/pkgexports.mjs'; -import { loadMissing } from '../fixtures/pkgexports-missing.mjs'; +import { loadMissing, loadFromNumber } from '../fixtures/pkgexports-missing.mjs'; strictEqual(asdf, 'asdf'); strictEqual(asdf2, 'asdf'); @@ -13,3 +13,8 @@ loadMissing().catch(mustCall((err) => { ok(err.message.toString().startsWith('Package exports')); ok(err.message.toString().indexOf('do not define a \'./missing\' subpath')); })); + +loadFromNumber().catch(mustCall((err) => { + ok(err.message.toString().startsWith('Package exports')); + ok(err.message.toString().indexOf('do not define a \'./missing\' subpath')); +})); diff --git a/test/fixtures/node_modules/pkgexports-number/hidden.js b/test/fixtures/node_modules/pkgexports-number/hidden.js new file mode 100644 index 0000000000..c04e6ee618 --- /dev/null +++ b/test/fixtures/node_modules/pkgexports-number/hidden.js @@ -0,0 +1 @@ +module.exports = 'not-part-of-api'; diff --git a/test/fixtures/node_modules/pkgexports-number/package.json b/test/fixtures/node_modules/pkgexports-number/package.json new file mode 100644 index 0000000000..315f39a66e --- /dev/null +++ b/test/fixtures/node_modules/pkgexports-number/package.json @@ -0,0 +1,3 @@ +{ + "exports": 42 +} diff --git a/test/fixtures/pkgexports-missing.mjs b/test/fixtures/pkgexports-missing.mjs index bbf123e330..ab7705a150 100644 --- a/test/fixtures/pkgexports-missing.mjs +++ b/test/fixtures/pkgexports-missing.mjs @@ -1,3 +1,7 @@ -export function loadMissing () { +export function loadMissing() { return import('pkgexports/missing'); } + +export function loadFromNumber() { + return import('pkgexports-number/hidden.js'); +}