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

Package.json exports field defines extensionless export that errors in pure ESM environments #920

Closed
scalvert opened this issue Jul 15, 2022 · 1 comment

Comments

@scalvert
Copy link
Contributor

The fixed export of release/test/util in #539 helped consumers access the test utils again (thank you!). Using an extensionless export, however, has complicated compatibility across multiple release-it versions. Pure ESM release-it plugins, when testing using ava, will error with extensionless sub-paths.

https://github.com/rwjblue/release-it-lerna-changelog/runs/7347409577?check_suite_focus=true

> release-it-lerna-changelog@4.0.1 test /home/runner/work/release-it-lerna-changelog/release-it-lerna-changelog
> ava
  Uncaught exception in test.js
  Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/runner/work/release-it-lerna-changelog/release-it-lerna-changelog/node_modules/release-it/test/util' is not supported resolving ES modules imported from /home/runner/work/release-it-lerna-changelog/release-it-lerna-changelog/test.js
  Did you mean to import release-it-lerna-changelog/release-it-lerna-changelog/node_modules/release-it/test/util/index.js?
  ✖ test.js exited with a non-zero exit code: 1

The Node documentation encourages the use of extension-based exports when those exports point to a single file, as is the case here. I've tested converting the package's exports to use an extension instead of a sub-path, and it ensures correct compatibility across release-it versions 14-latest (15.1.1).

Change:

  "exports": {
    ".": "./lib/index.js",
    "./test/util/index.js": "./test/util/index.js"
  },

If you'd be open to it, I'll open a PR making that change in the latest version.

@webpro
Copy link
Collaborator

webpro commented Jul 16, 2022

Thanks @scalvert. Agreed, just patched it in v15.1.2. Since it's a test util I consider this not a breaking change.

scalvert added a commit to scalvert/release-it that referenced this issue Jul 17, 2022
This change slightly adjusts the exports in this repo's package.json in order to expose the required test utilities to consumers.

While it works to provide the alias within release-it@529bc1f, it's slightly confusing to consumers who expect the export to map to a real path on disc.

Relates to release-it#920 and tweaks release-it@529bc1f to use correct path.
webpro pushed a commit that referenced this issue Jul 20, 2022
This change slightly adjusts the exports in this repo's package.json in order to expose the required test utilities to consumers.

While it works to provide the alias within 529bc1f, it's slightly confusing to consumers who expect the export to map to a real path on disc.

Relates to #920 and tweaks 529bc1f to use correct path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants