Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/log-package-resolution-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-native-node-api": patch
---

Log the original package resolution error during dependency scanning so invalid package entry points include the missing path.
30 changes: 30 additions & 0 deletions packages/host/src/node/path-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import assert from "node:assert/strict";
import { describe, it } from "node:test";
import path from "node:path";
import fs from "node:fs";
import { createRequire } from "node:module";
import fswin from "fswin";

import {
determineModuleContext,
findNodeApiModulePaths,
findNodeAddonForBindings,
findPackageDependencyPaths,
resolvePackageRoot,
getLibraryName,
isNodeApiModule,
stripExtension,
Expand Down Expand Up @@ -355,6 +357,34 @@ describe("findPackageDependencyPaths", () => {
});
});

describe("resolvePackageRoot", () => {
it("logs the original package resolution error", (context) => {
const tempDir = setupTempDirectory(context, {
"node_modules/broken-package/package.json": JSON.stringify({
name: "broken-package",
main: "missing.js",
}),
});
const requireFromRoot = createRequire(path.join(tempDir, "noop.js"));
const debug = context.mock.method(console, "debug", () => {});

assert.equal(
resolvePackageRoot(requireFromRoot, "broken-package"),
undefined,
);
assert.equal(debug.mock.callCount(), 1);

const call = debug.mock.calls[0];
assert(call);
assert.equal(call.arguments.length, 1);
assert.equal(typeof call.arguments[0], "string");
assert.match(
String(call.arguments[0]),
/Failed to resolve package root for "broken-package": Cannot find module .*broken-package[\\/]missing\.js/,
);
});
});

describe("findNodeApiModulePaths", () => {
it("should find .apple.node paths", async (context) => {
const tempDir = setupTempDirectory(context, {
Expand Down
7 changes: 5 additions & 2 deletions packages/host/src/node/path-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ export function resolvePackageRoot(
try {
const resolvedPath = requireFromPackageRoot.resolve(packageName);
return packageDirectorySync({ cwd: resolvedPath });
} catch {
// TODO: Add a debug log here
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
console.debug(
`Failed to resolve package root for "${packageName}": ${message}`,
);
return undefined;
}
}
Expand Down