Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to resolve self-referring "subpath exports" from within a haste module #1222

Open
kraenhansen opened this issue Feb 15, 2024 · 1 comment

Comments

@kraenhansen
Copy link
Contributor

kraenhansen commented Feb 15, 2024

Do you want to request a feature or report a bug?

I'd like to report a bug.

What is the current behavior?

Performing a self-referring subpath import (i.e. import "my-lib/some-sub-path") from within a package (in this example "my-lib") while the package is considered a haste module (included in watchFolders) I'm experiencing the following error:

Error: Unable to resolve module my-lib/subpath from /Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-lib/index.js: my-lib/subpath could not be found within the project.
> 1 | import { greeting } from "my-lib/subpath";
    |                           ^
  2 | console.log(greeting);
  3 |
    at ModuleResolver.resolveDependency (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:138:15)
    at DependencyGraph.resolveDependency (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
    at /Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/lib/transformHelpers.js:156:21
    at resolveDependencies (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:42:25)
    at visit (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:83:30)
    at async Promise.all (index 0)
    at async visit (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:92:5)
    at async Promise.all (index 0)
    at async buildSubgraph (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/DeltaBundler/buildSubgraph.js:103:3)
    at async Graph._buildDelta (/Users/kraen.hansen/Projects/metro-self-ref-subpath-issue/my-app/node_modules/metro/src/DeltaBundler/Graph.js:157:22)

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

  1. Clone the reproduction repository:
    git clone https://github.com/kraenhansen/metro-issue-1222
    
  2. npm install (yarn doesn't create a symlink for the "../my-lib" dependency of "my-app").
  3. npm test to observe the error above.

What is the expected behavior?

I would expect the subpath to resolved, just as if the my-app/index.js file is updated to import "my-lib/subpath" directly.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

// metro.config.js
const path = require("path");

module.exports = {
  watchFolders: [
    path.resolve(__dirname, "../my-lib"),
  ],
  resolver: {
    unstable_enableSymlinks: true,
    unstable_enablePackageExports: true,
    enableGlobalPackages: false,
  }
};
  • Metro v0.80.6
  • node -v v20.10.0
  • npm -v 10.2.3
  • MacOS

Additional information

This bug feels related to #1128, as that was also dealing with subpath exports and haste modules.

@kraenhansen
Copy link
Contributor Author

kraenhansen commented Feb 15, 2024

@robhogan you mentioned on #1136 (comment) that enableHastePackages is default-off from Metro 0.79, am I missing something obvious / context here?

This issue persists even when I explicitly set resolver.enableGlobalPackages = false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant