Skip to content

package.exports: false is not working with module loader #32107

Closed
@JLHwung

Description

Edits:

If you come here via search engine and @babel/* complaints such errors after you upgraded to node.js 12.17.0 or 13.10.0, please update @babel/helper-compilation-targets to latest version.

If you are not using babel directly, please update your build infra (react-scripts, vue-cli and others to name) to latest version. If they doesn't work, the last resort is to remove your package lockfiles and re-install.

--- Original Post ---

  • Version: v13.10.1
  • Platform: Darwin jh.local 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64 x86_64
  • Subsystem: ES Modules

What steps will reproduce the bug?

  1. Create a package foo, with package.json as
{
  "exports": false
}
  1. add a test file test.js.
require("foo")

How often does it reproduce? Is there a required condition?

Must reproduce

What is the expected behavior?

It should load successfully according to the docs

If a package has no exports, setting "exports": false can be used instead of "exports": {} to indicate the package does not intend for submodules to be exposed.

What do you see instead?

It throws

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in /path/to/foo/package.json

Additional information

exports: {} also throws.
exports: null looks good to me but it is undocumented.

The issue is firstly reported in babel/babel#11216, we had changed exports: false to exports: { ".": "./lib/index.js" } for backward compatibility to Node.js 13.0-13.1. But I don't expect exports: false will break on Node.js 13.10

I am not familiar with ES modules spec. So if this behaviour is intended, please update the docs.

Metadata

Labels

docIssues and PRs related to the documentations.esmIssues and PRs related to the ECMAScript Modules implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions