-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Support package.json exports "Alternatives" #5052
Comments
Do you have a real package json with real use case for me to test on? |
Hi @Boshen, I can't make our repository available, but I created a minimal reproducible demo: rspack_export_alternatives.zip Instructions are in the README.md (and pasted here):
To reproduce, do the following:
This will create a Now, remove the Let me know if you need anything else, and thanks for getting back to me so quickly! |
I know this day will come when I was implementing this feature, but not this soon - because I found a discrepancy / compatibility issue between the implementations between webpack/enhanced-resolve and node.js ESM. This is going to be a long explanation detailing what's going on with this requirement, so please bear with me. Let's start with the X/Y problem: The
|
Andrew replied:
|
nodejs/node#37928 (comment) It's a known issue in Node.js side and It seems Node.js current behavior is not useful for real world application and Webpack and Typescript all choose fallback style, so It seems following enhanced-resolve's way is better for Rspack. |
For TypeScript, it’s a bug when it happens in |
that is interesting,@alexander-akait sorry to bother you,I am also not sure whether webpack current fallback strategy is a feature or bug,or is aligning resolve algorithm with Node.js is a goal of enhanced-resolve? |
That's intresting, especial nodejs/node#37928 (comment), I want to say it is not a bug, the fallback style is useful and provide more power
We literally read it as - if you get an error then continue
I disagree with that, because what's the point using an array of alternatives if we will take the first valid target. I think this sentence explains the logic pretty clearly (nodejs/node#37928):
|
@alexander-akait thanks for your detail explanation, @Boshen since Typescript(moduleResolution set to |
Given this twitter thread and my understanding of future compatibility, my advice is also do not use export arrays. Remember, packages are published to public / private npm registries, anything that do not conform to the specification will break future compatibility. It does not matter whether the given feature is useful or not. As for alternative solutions to what I believe what the actual problem is, we have:
|
It might be useful to ping someone from the Node.js team here because I want to hear the real reason why it was implemented this way |
This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing due to lack of actionable items. Please see all the linked issues in bluwy/publint#92 |
@Boshen
reproduction: Brief:
tools: {
rspack: config => {
config.resolve = {
...(config.resolve ?? {}),
tsConfig: {
configFile: path.resolve(__dirname, './tsconfig.json'),
references: 'auto',
},
};
return config;
}
} Run cd examples/basic-app/
pnpm start Then the dev server fails to resolve the dependency. I think I missed some points here. Thank you for your advice! |
@yf-yang Can you create a new issue with the expected outcome? This issue shouldn't be used to triage your issue. |
Sure I'll give it a try and then create another issue if stuck. Thank you for your attention |
@yf-yang we are reconsidering support this feature |
since webpack deprecate alternative in webpack/enhanced-resolve#429, Rspack's current behavior is same as latest webpack |
What problem does this feature solve?
webpack supports Alternatives in package.json#exports fields: https://webpack.js.org/guides/package-exports/#alternatives
This allows us to import from one path, if possible, and fallback to another path if required. Currently in rspack, this will fail with a
Failed to resolve
in case the first occurance (./dist/index.js
) does not exist. It works in webpack however.What does the proposed API of configuration look like?
No API required.
The text was updated successfully, but these errors were encountered: