Skip to content

fix: support react native 0.79 #2233

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

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

Conversation

vonovak
Copy link
Collaborator

@vonovak vonovak commented Apr 17, 2025

Description

This PR is to discuss compatibility for React Native 0.79, working around dual-package hazard that's happening since support for package exports was enabled by default in facebook/metro#1448.

The issue can be reproduced in #2231.

There are 3 kinds of fixes:

  • (1) specify custom export entry for react-native (workaround in library)
  • (2) specify custom resolveRequest in metro config (workaround in userland):
config.resolver.resolveRequest = (context, moduleImport, platform) => {
  switch (moduleImport) { 
    case '@lingui/react':
      return { type: 'sourceFile', filePath: require.resolve('@lingui/react') };

    default:
      return context.resolveRequest(context, moduleImport, platform);
  }
};
  • (3) fix babel plugin transforms (@lingui/react/macro). The comment I got:

Probably, the import is getting replaced but dropping the source import loc, which Metro needs to map the dependency to the original import
The good news is that category of problem should go away when we move off the Babel ESM transform and we don’t need to rely on source mappings to determine the original import style.
For now the best fix for lingui-js would be to preserve the source loc when it replaces an import - which it definitely should be doing anyway.

it looks like path.insertAfter in addImport is what breaks Metro bundler

Types of changes

  • Bugfix (non-breaking change which fixes an issue)

Fixes # (issue)

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

Copy link

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview Apr 17, 2025 7:34am

@vonovak vonovak changed the title Support React Native 0.79 fix: support react native 0.79 Apr 17, 2025
Copy link

size-limit report 📦

Path Size
packages/core/dist/index.mjs 2.91 KB (0%)
packages/detect-locale/dist/index.mjs 618 B (0%)
packages/react/dist/index.mjs 1.35 KB (0%)

@@ -42,6 +42,7 @@
},
"exports": {
".": {
"react-native": "./dist.index.cjs",
Copy link
Collaborator

Choose a reason for hiding this comment

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

the path is incorrect here.

@timofei-iatsenko
Copy link
Collaborator

Could it be solved from documentation perspective? How other packages used in react native world handle the issue?

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