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:
|
it("exports a callable sum function", () => { |
|
const exampleAddon = |
|
/* eslint-disable-next-line @typescript-eslint/no-require-imports -- TODO: Determine why a dynamic import doesn't work on Android */ |
|
require("@react-native-node-api/ferric-example") as typeof import("@react-native-node-api/ferric-example"); |
|
const result = exampleAddon.sum(1, 3); |
|
if (result !== 4) { |
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.
Tracking the
TODOinapps/test-app/App.tsx.The
ferric-exampletest has to userequire()— with an ESLint disable for@typescript-eslint/no-require-imports— because a dynamicimport()of the same addon does not work on Android:react-native-node-api/apps/test-app/App.tsx
Lines 78 to 83 in 29a527d
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:
packages/host/src/node/babel-plugin/plugin.tsrewritesrequire("./addon.node")but leavesimport("./addon.node")untransformed — the plugin matchesrequirecall expressions, so a dynamic import may simply never be turned into arequireNodeAddon()call.Outcome should be either a fix (most likely: handle
import()in the Babel plugin alongsiderequire()) or a documented limitation, so theeslint-disablecan carry a real explanation instead of an open question.