Skip to content

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

Description

@shirakaba

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.

} catch {
// TODO: Add a debug log here

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'"}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions