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

Add ./package.json as an export entry #1109

Merged
merged 1 commit into from Mar 26, 2024
Merged

Conversation

ahmedelgabri
Copy link
Contributor

This will avoid breaking older tools that try to read package.json files from packages using package name instead of absolute path.

Because when exports is set, accessing files that's not specified in the exports property is not allowed by node and it will throw a ERR_PACKAGE_PATH_NOT_EXPORTED error (rightly so).

This easily reproducible in the node repl.

This will throw

require.resolve('immer/package.json')

This will not throw

require.resolve('./node_modules/immer/package.json')

Screenshot 2024-03-20 at 10 50 05

Something similar has been mentioned in this great article https://blog.isquaredsoftware.com/2023/08/esm-modernization-lessons/#issue-history by @markerikson (sorry for the ping, feel free to ignore) when he worked on modernizing @reduxjs/toolkit (which depends on immer and this is how I found the issue)

Similar issues in the wild on GitHub for Package subpath './package.json' is not defined by "exports" https://github.com/search?q=%22Package+subpath+%27.%2Fpackage.json%27+is+not+defined+by+%22exports%22%22&type=issues

add `./package.json` as an export entry
@mweststrate
Copy link
Collaborator

Thanks! Let's hope this doesn't explode something for someone somewhere. Given that it touches package config, it probably will🥹

@mweststrate mweststrate merged commit baa387a into immerjs:main Mar 26, 2024
1 check passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8356888414

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.793%

Totals Coverage Status
Change from base Build 8240372216: 0.0%
Covered Lines: 647
Relevant Lines: 648

💛 - Coveralls

@ahmedelgabri ahmedelgabri deleted the patch-1 branch March 26, 2024 20:36
Copy link
Contributor

🎉 This PR is included in version 10.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants