immerjs / immer

Create the next immutable state by mutating the current one
https://immerjs.github.io/immer/
MIT License
27.5k stars 850 forks source link

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

Closed ahmedelgabri closed 5 months ago

ahmedelgabri commented 5 months ago

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

mweststrate commented 5 months ago

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

coveralls commented 5 months ago

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


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

💛 - Coveralls
github-actions[bot] commented 4 months ago

:tada: This PR is included in version 10.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: