Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Would be good to have a debug log for failed module resolution

未关闭
#369 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
55/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
停滞
领域
tooling

调研方向

从 packages/host/src/node/path-utils.ts 中的 resolvePackageRoot 以及其 catch 块中的 TODO 开始。重现 issue 中所示的 index.cjs 解析失败,然后验证解析失败会输出调试日志,同时函数仍返回 undefined。

由索引模型根据 Issue 内容生成。

描述

good first issue

Just got tripped up by this, but figured it out (my npm package was missing an index.cjs file). Would've figured it out sooner if we'd had an error log (which indeed was TODO), so just tracking this.

https://github.com/callstackincubator/react-native-node-api/blob/80ae73b404cb57d34be75b08dd2ed5197f988595/packages/host/src/node/path-utils.ts#L262-L263

export function resolvePackageRoot(
  // createRequire(path.join("/Users/jamie/Documents/git/expo-macos-nativescript", "noop.js"))
  requireFromPackageRoot: NodeJS.Require,
  // "@nativescript/macos-node-api"
  packageName: string,
): string | undefined {
  try {
    const resolvedPath = requireFromPackageRoot.resolve(packageName);
    return packageDirectorySync({ cwd: resolvedPath });
  } catch {
    // TODO: Add a debug log here
    return undefined;
  }
}
Error: Cannot find module '/Users/jamie/Documents/git/expo-macos-nativescript/node_modules/@nativescript/macos-node-api/index.cjs'
    at createEsmNotFoundErr (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/cjs/loader.js:1493:15)
    at finalizeEsmResolution (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/cjs/loader.js:1482:9)
    at resolveExports (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/cjs/loader.js:685:14)
    at Module._findPath (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/cjs/loader.js:752:31)
    at Module._resolveFilename (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/cjs/loader.js:1441:27)
    at require.resolve (/Users/jamie/Documents/git/expo-macos-nativescript/lib/internal/modules/helpers.js:163:19)
    at eval (<node_internals>/eval-b052276f.repl:1:30)
    at resolvePackageRoot (/Users/jamie/Documents/git/expo-macos-nativescript/node_modules/react-native-node-api/dist/node/path-utils.js:215:9)
    at /Users/jamie/Documents/git/expo-macos-nativescript/node_modules/react-native-node-api/dist/node/path-utils.js:247:40
    at Array.flatMap (<anonymous>) {code: 'MODULE_NOT_FOUND', path: '/Users/jamie/Documents/git/expo-macos-nativescript/node_modules/@nativescript/macos-node-api', stack: "Error: Cannot find module '/Users/jamie/Docum….js:247:40
    at Array.flatMap (<anonymous>)", message: "Cannot find module '/Users/jamie/Documents/g…ules/@nativescript/macos-node-api/index.cjs'"}
主要语言
TypeScript
星标
188
派生
10
平均合并
2 天 17 小时
30 天内合并 PR
3

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstackincubator/react-native-node-api 的其他 Issue

查看 callstackincubator/react-native-node-api 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。