Skip to content

Conversation

@macksal
Copy link
Contributor

@macksal macksal commented Aug 25, 2025

Description of change

Importing typeorm in a react native app (metro@0.82.4, react-native@0.79.5, expo@53.0.22) generates this warning:

WARN  Attempted to import the module "-snip-/node_modules/typeorm" which is listed in the "exports" of "-snip-/node_modules/typeorm", however no match was resolved for this request (platform = ios). Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.

This is happening because Metro by default now looks at package.json exports to find which file to use when a module is imported in react native.

Previously, Metro would consider the browser property in package.json. However, in the new "Package Exports" feature, it only looks for the require or react-native conditions inside the exports property, as well as optional extra conditions on a per-platform basis. If none of those conditions can be found, it will fall back to the old behaviour, but continue to issue a warning.

An easy fix is to add the react-native condition as part of the exports field (Implemented here). In the end, the behaviour is the same (since the fallback behaviour imports the browser code anyway) but suppresses the warning at runtime. This is non-invasive and should have no impact on other platforms.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Summary by CodeRabbit

  • New Features
    • Improved React Native compatibility by adding a dedicated React Native export, enabling seamless module resolution in React Native projects.
    • Reduces the need for manual configuration or aliasing when integrating the package in mobile apps.
    • Ensures the correct browser-friendly build is selected for React Native environments for more reliable behavior across platforms.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 25, 2025

Walkthrough

Added a react-native export mapping to the root export in package.json, directing React Native consumers to ./browser/index.js via a default field.

Changes

Cohort / File(s) Change Summary
Package configuration
package.json
Introduced exports["."]["react-native"] = { "default": "./browser/index.js" }. No other fields modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A nibble of JSON, a hop in the night,
I mapped a new path to make bundles light.
React Native knocks—“this way,” I say,
Toward browser fields where modules play.
Ears up, merge down, carrots in sight—
Configs aligned, we ship with delight! 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
package.json (3)

22-24: Prefer a simple string mapping for react-native (fewer moving parts)

Metro and Node both accept a string on "react-native". Since you route both import and require to the same file, a single string is clearer and avoids nesting with an inner "default".

Apply this minimal change:

-      "react-native": {
-        "default": "./browser/index.js"
-      },
+      "react-native": "./browser/index.js",

Alternative (if you want to be fully explicit about modes):

-      "react-native": {
-        "default": "./browser/index.js"
-      },
+      "react-native": {
+        "import": "./browser/index.js",
+        "require": "./browser/index.js"
+      },

36-45: Consider whether subpath imports need an RN condition

You already expose wildcards via "./.js" and "./". If RN consumers (or your own docs) encourage subpath imports, Metro won’t see a "react-native" condition on those entries. It should still resolve via "import"/"require", but if you’ve seen similar warnings for subpaths, mirroring the RN condition on "./*" could be warranted.

Happy to draft a scoped follow-up that adds "react-native" only where necessary to avoid noise.


79-96: Optional: note this in CHANGELOG as a developer-facing behavior tweak

Though runtime behavior is unchanged, RN consumers benefit from the warning removal. A brief CHANGELOG entry under "Fixes" will help downstream maintainers understand the change.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 22b26d1 and 74248cf.

📒 Files selected for processing (1)
  • package.json (1 hunks)
🔇 Additional comments (3)
package.json (3)

20-35: Double-check type resolution for TS consumers under RN

You keep "types": "./index.d.ts" at the same level as the conditional map, which TypeScript uses independently of the selected runtime branch. That’s generally correct. Just confirm that the browser entry’s surface matches the declarations (it should, given the existing browser map).

If you want to be extra safe, add a quick TS compile check in CI that imports "typeorm" with a React Native tsconfig (moduleResolution: bundler or node16) to ensure d.ts alignment.


48-72: Sanity check: RN runtime compatibility of the browser bundle

Routing RN to "./browser/index.js" relies on the browser build’s assumptions: no Node core APIs and disabled server-only drivers (which you already alias out via the "browser" field). This is the right target for Hermes/JSC. Just ensure any new code paths continue to avoid Node-only modules.

If you have a minimal RN app repro, import "typeorm" and ensure bundling succeeds and no Metro warnings remain on:

  • Metro 0.82.4 (as reported)
  • At least one earlier minor (e.g., 0.81.x) to gauge backward behavior

22-24: Validate package resolution with Metro and Node

The "react-native": { "default": "./browser/index.js" } export condition correctly targets Metro’s resolver without affecting Node (unknown conditions are ignored).

Automated verification failed in this sandbox (missing Python for native modules and no local gulp). Please manually verify the resolution outputs:

• Ensure packaging succeeds:

  • Install Python (≥3.x) so native dependencies (e.g. better-sqlite3) can build.
  • Run:
    npm ci
    npm run package
  • Confirm that build/package/ contains the packaged files.

• Test Node vs. React Native conditions using an absolute path for createRequire:

node -p "const {createRequire} = require('node:module'); const {resolve} = require('path'); const r = createRequire(resolve(__dirname,'build/package')); console.log('node-default:', r.resolve('typeorm'))"
node --conditions=react-native -p "const {createRequire} = require('node:module'); const {resolve} = require('path'); const r = createRequire(resolve(__dirname,'build/package')); console.log('react-native:', r.resolve('typeorm'))"

Expected results:

  • node-default./index.js (or ./index.mjs for ESM)
  • react-native./browser/index.js

File: package.json
Lines: 22-24

       "react-native": {
-        // missing before
         "default": "./browser/index.js"
       },

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 25, 2025

typeorm-sql-js-example

npm i https://pkg.pr.new/typeorm/typeorm@11623

commit: 74248cf

Copy link
Collaborator

@sgarner sgarner left a comment

Choose a reason for hiding this comment

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

I'm not familiar with Metro or React Native, but the fix looks fine for the issue as described.

@macksal Have you been able to test that this works?

Thanks for your contribution!

@coveralls
Copy link

Coverage Status

coverage: 76.348%. remained the same
when pulling 74248cf on macksal:fix/package-exports
into 22b26d1 on typeorm:master.

@macksal
Copy link
Contributor Author

macksal commented Aug 26, 2025

@sgarner yep, patching this into my installed copy removes the warning and my typeorm imports are still functional. Happy for this to be merged. There are a fair few consumers of typeorm through expo-sqlite, who will be upgrading to expo@53. This should help to pre-empt any questions about the warning.

It might not work for subpath imports like import {DataSource} from "typeorm/X", but from what I can tell (i) it's not a common use case, and (ii) that style of import isn't rewritten to ./browser/X in the existing setup anyway. (There actually might be an existing dual-package hazard if those imports are used in a browser-like environment). Either way, it's not affected by the change here since we're just copying the default behaviour from older versions of metro.

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

Thanks for your help @macksal

@sgarner sgarner merged commit 6965fa2 into typeorm:master Aug 30, 2025
58 checks passed
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
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.

5 participants