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

fix: move package exports for react native #14136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timostroehlein
Copy link

@timostroehlein timostroehlein commented Jan 13, 2025

Description of changes

Currently the react-native package exports are incorrectly order. The react-native package export should come before the require and import exports, since the condition names are resolved in order and default to ['require', 'react-native'].

Description of how you validated changes

I've only validated the changes by adjusting the exports using yarn patch in our repo.

Checklist

  • PR description included

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@HuiSF
Copy link
Member

HuiSF commented Jan 13, 2025

Hi @timostroehlein thank you for opening this PR, much appreciated. Have you actually encountered react-native bundle build issues with the existing exports settings?

Following the Metro documentation, unstable_conditionNames takes only effect when unstable_enablePackageExports is set to true. Do you currently enable this option?

@timostroehlein
Copy link
Author

Hi @HuiSF, the issue actually isn't build related. The main issue was the inconsistency between the exports. Let me try to explain the main issue. The issue only happens if unstable_enablePackageExports is enabled and unstable_conditionNames is set to ['require', 'react-native'].

For example the @aws-amplify/core package doesn't define any package exports, but has a react-native export field at root exporting ts files. The order of the exports on root doesn't matter, so even with package exports enabled, metro will import from the react-native entry point, which is correct in this case.

On the other hand, most of the packages, e.g. the @aws-amplify/auth package does define package exports. Those exports are resolved in order, since the unstable_conditionNames in metro are set to ['require', 'react-native'] (order doesn't matter here), it will import from the require/cjs import. That isn't the expected behaviour, since we want to import from react-native.

In our case the Amplify config was undefined when calling signIn from @aws-amplify/auth, even though we called Amplify.configure, caused by both cjs and ts inconsistently referenced.

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

Successfully merging this pull request may close these issues.

2 participants