Skip to content

fix: React-Native package exports #4887

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

aryaemami59
Copy link
Member

@aryaemami59 aryaemami59 self-assigned this Mar 11, 2025
Copy link

codesandbox bot commented Mar 11, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

codesandbox-ci bot commented Mar 11, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit 17fed4b
🔍 Latest deploy log https://app.netlify.com/sites/redux-starter-kit-docs/deploys/68191e4cd9cf7b00082fc287
😎 Deploy Preview https://deploy-preview-4887--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@markerikson
Copy link
Collaborator

@aryaemami59 can you summarize the package changes and why they improve things?

@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from 2cecb47 to 25f7b50 Compare March 16, 2025 11:06
@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from 25f7b50 to c67da92 Compare March 31, 2025 18:22
@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from c67da92 to 2ebf48c Compare April 11, 2025 10:07
@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from 2ebf48c to c944724 Compare April 27, 2025 12:18
@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch 2 times, most recently from 9de562c to f9f283d Compare May 1, 2025 15:36
@BenQoder
Copy link

BenQoder commented May 2, 2025

This fix is essential, Because in the latest version of Expo (Expo 53); It logs this warning uncountable times.

I hope it is reviewed and merged soon

Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the tsup changes (was this just a port to TS or bigger changes?) but the exports field changes generally seem reasonable. This should at least be a minor bump, though.

"types": "./../dist/query/index.d.ts",
"exports": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping the exports field should be okay - a bundler that supports exports should look at the root-level package.json.

@@ -4,16 +4,9 @@
"description": "",
"type": "module",
"module": "../dist/query/rtk-query.legacy-esm.js",
"main": "../dist/query/cjs/index.js",
"main": "./../dist/query/rtk-query.modern.mjs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here be dragons - this switches from CJS to ESM. Probably be fine, since only outdated bundlers would look at this file at all, but pointing it out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this vitest will fail unless we explicitly specify resolve.mainFields in vitest config files. Still not entirely sure why this happens, I know it's vite related and with this change added everything seems to work okay.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the flip side, this was here to keep Webpack 4 working.

Obviously at this point we shouldn't want to care about Webpack 4 much, but that's why it's here.

Why is Vitest looking at this field at all anyway? Shouldn't it be following exports instead and not even looking at this file?

@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from f9f283d to e4b5479 Compare May 3, 2025 23:47
markerikson
markerikson previously approved these changes May 4, 2025
@@ -4,16 +4,9 @@
"description": "",
"type": "module",
"module": "../dist/query/rtk-query.legacy-esm.js",
"main": "../dist/query/cjs/index.js",
"main": "./../dist/query/rtk-query.modern.mjs",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why did this change? main should point to a CJS file as far as I know.

@@ -4,16 +4,9 @@
"description": "",
"type": "module",
"module": "../dist/query/rtk-query.legacy-esm.js",
"main": "../dist/query/cjs/index.js",
"main": "./../dist/query/rtk-query.modern.mjs",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the flip side, this was here to keep Webpack 4 working.

Obviously at this point we shouldn't want to care about Webpack 4 much, but that's why it's here.

Why is Vitest looking at this field at all anyway? Shouldn't it be following exports instead and not even looking at this file?

@markerikson markerikson dismissed their stale review May 4, 2025 00:11

accidental

@aryaemami59 aryaemami59 force-pushed the fix/react-native-package-exports branch from e4b5479 to 595db02 Compare May 4, 2025 17:45
@markerikson
Copy link
Collaborator

Spent a couple hours poking at this and concluded that Vitest does not seem to be looking at exports for those nested entry points :(

I honestly still don't know why. This is the closest I could find:

but that just says "it uses the Node resolution algorithm", which ought to still involve exports I'd think.

As a result, we were seeing a module mismatch - it was importing redux-toolkit.modern.mjs, but rtk-query.development.cjs, and thus Bad Things happened.

What we've ended up on is specifying resolve: {mainFields: ["module"]}, which forces it to stop looking at the main field and land on module, which currently points to our legacy-esm.js artifacts. That's not good and will almost definitely bite us at some point, but it lets the "test against dist" test pass for now.

@markerikson markerikson force-pushed the fix/react-native-package-exports branch from d96d5cd to 7c1eacc Compare May 5, 2025 20:19
@markerikson markerikson force-pushed the fix/react-native-package-exports branch from 7c1eacc to 17fed4b Compare May 5, 2025 20:23
@markerikson
Copy link
Collaborator

Further updates:

After some discussion on Bluesky, I wondered if this was specific to either Yarn or NPM in general, due to package.json also having the name: "@reduxjs/toolkit" value, and thus maybe preventing Vitest from going into node_modules to find the installed version.

After further random flailing and changing settings investigation, I concluded that this is indeed the case. So, instead of adding a TEST_DIST-specific alias, what we really need is to temporarily alter the package name field so that Vitest is forced to look inside of node_modules instead. Did that in the tests.yml workflow.

I've confirmed (locally at least) that this does indeed result in Vitest loading the rtk-query.modern.mjs artifact as we would want.

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