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

resolve to wrong module with aliasFields #4446

Closed
Tracked by #4327
ahabhgk opened this issue Oct 26, 2023 · 3 comments · Fixed by #4952
Closed
Tracked by #4327

resolve to wrong module with aliasFields #4446

ahabhgk opened this issue Oct 26, 2023 · 3 comments · Fixed by #4952
Assignees
Labels
team The issue/pr is created by the member of Rspack.

Comments

@ahabhgk
Copy link
Contributor

ahabhgk commented Oct 26, 2023

webpack-test/cases/resolving/browser-field should pass

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Oct 26, 2023
@ahabhgk ahabhgk changed the title resolve to wrong module with aliasField resolve to wrong module with aliasFields Oct 26, 2023
@Boshen
Copy link
Contributor

Boshen commented Oct 26, 2023

Here are the missing pieces:

  1. node_modules is missing from https://github.com/web-infra-dev/rspack/tree/main/webpack-test/cases/resolving/browser-field

  2. To pass this:

    expect(require("replacing-module1")).toBe("new-module");

We need to set browserField: true in the webpack config

/**
* This is `aliasField: ["browser"]` in webpack, because no one
* uses aliasField other than "browser". ---@bvanjoi
*/
browserField: z.boolean().optional(),

But it seems like there is a big mismatch between all these configs - See https://www.rspack.dev/config/resolve.html#resolvealiasfield and https://webpack.js.org/configuration/resolve/#resolvealiasfields


FYI oxc_resolver reads alias_fields

let alias_fields = (if options.browser_field.unwrap_or(true) {
vec!["browser".to_string()]
} else {
vec![]
})
.into_iter()
.map(|x| vec![x])
.collect();

@Boshen
Copy link
Contributor

Boshen commented Oct 26, 2023

I'm still investigating on how to pass

if (Math.random() < 0) require("recursive-file/a");
if (Math.random() < 0) require("recursive-file/b");
if (Math.random() < 0) require("recursive-file/c");
if (Math.random() < 0) require("recursive-file/d");

but it seems the rspack suite commented it out:

// TODO: missing module
// if (Math.random() < 0) require("recursive-file/a");
// if (Math.random() < 0) require("recursive-file/b");
// if (Math.random() < 0) require("recursive-file/c");
// if (Math.random() < 0) require("recursive-file/d");


enhanced-resolve will throw an infinite recursion error, while oxc_resolver will resolve it to webpack-test/cases/resolving/browser-field/node_modules/recursive-file/a.js

@Boshen
Copy link
Contributor

Boshen commented Oct 26, 2023

For debugging what's being passed into oxc_resolver:

cd webpack-test
OXC_RESOLVER=TRACE pnpm t -- -t "resolving browser-field" | grep  alias_fields

and you should see alias_fields: [["browser"]]

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants