Yarn 2: rework imports in webpack preview virtual module to fix compatibility #10305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: #10094
Also related to #9527
What I did
Using ES6 import directly in
preview.js-generated-config-entry.js
module definition is causing the following error when using Yarn 2:This is because the code of the virtual module is importing
@storybook/client-api
and@storybook/client-logger
. When the code is executed these packages are required in the context of SB user project and not in the one of@storybook/core
causing Yarn 2 to throw.To avoid this, we are now resolving theses deps directly when webpack config is built (so in
@storybook/core
context) and then using the resolved values in the virtual module.I didn't find a better way than adding a check on PnP usage to avoid these errors when building React SB example in our monorepo:
How to test
All tests should still pass and sadly, for now, there is no Yarn 2 automated test.