Dynamic `import()` of a Node-API addon doesn't work on Android

オープン
#416 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
android, babel, react-native, typescript

調査の方向性

apps/test-app/App.tsx の TODO から始め、Android での動的 import の失敗を再現し、それが reject するのか throw するのか、またそのメッセージを記録してください。次に packages/host/src/node/babel-plugin/plugin.ts を調べ、require() と import() の処理を比較してください。完了条件は、Android で動的 import が動作するか、または制限とその原因が、eslint-disable の意味のある説明を含めて文書化されていることです。

索引モデルが issue の本文から書いたものです。

説明

Android 🤖 Host 🏡

Tracking the TODO in apps/test-app/App.tsx.

The ferric-example test has to use require() — with an ESLint disable for @typescript-eslint/no-require-imports — because a dynamic import() of the same addon does not work on Android:

https://github.com/callstackincubator/react-native-node-api/blob/29a527d87fa8cb965b0048b1b4c1cff2b0eab281/apps/test-app/App.tsx#L78-L83

Nobody has established why. It matters beyond the test app: consumers writing modern ESM will reach for await import("some-addon") first, and if that silently fails on Android while working on iOS, it is a confusing first-run experience for exactly the audience this project targets.

Worth checking, roughly in order of likelihood:

  • Whether the Babel plugin in packages/host/src/node/babel-plugin/plugin.ts rewrites require("./addon.node") but leaves import("./addon.node") untransformed — the plugin matches require call expressions, so a dynamic import may simply never be turned into a requireNodeAddon() call.
  • Whether Metro's async-import handling on Android (inline requires / RAM bundles) defers the module in a way that breaks the TurboModule lookup.
  • Whether the failure is a rejected promise or a hard error, and what it actually says — the current comment records the symptom without the message.

Outcome should be either a fix (most likely: handle import() in the Babel plugin alongside require()) or a documented limitation, so the eslint-disable can carry a real explanation instead of an open question.

主要言語
TypeScript
スター
188
フォーク
10
平均マージ
2日 17時間
マージ済み PR(30日)
3

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

callstackincubator/react-native-node-api のほかの issue

callstackincubator/react-native-node-api の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。