-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
fix(v2): use require.resolve
for all webpack presets and plugins
#2788
fix(v2): use require.resolve
for all webpack presets and plugins
#2788
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 4943ae2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one thanks Sam!
Can we cut a new I'm using |
@pranaygp I tested on my local machine with various docusaurus packages unplugged and with my changes manually applied, and it can run in pnp loose mode. However I do not control the release process. |
We'll cut a new release within the next few days. |
@SamChou19815 I followed the instructions on your repo and it worked like a charm. It's rather annoying to have to use pnpify (I haven't needed it for anything else so far) but I'm glad it works for now |
@SamChou19815 would the previous plugin import syntax still work at all? If not we will have to update the docs asap to prevent more reports like #2825. I'm wondering whether we should change the default template's |
Managed to reproduce. Working on a fix. |
Ahh I forgot about that. Thanks for the reminder.
Got it, thank you! |
Motivation
Issue #2576 shows that docusaurus v2 doesn't work with Yarn v2 with pnp enabled.
This diff doesn't try to resolve the issue of the plugin system caused by the incompatibility: it can be solved by using the pnpLoose mode for now. Instead, it will fix some of the webpack plugin loading issue related to yarn pnp.
Inside the webpack config file, it refers to presets and plugins by strings, like
'@babel/plugin-transform-runtime'
. This setup happens to work with the traditional package managers' behavior onnode_modules
, which tries to hoist@babel/plugin-transform-runtime
to the top-levelnode_modules
if it can. However, it won't work under pnp, which expects that all dependencies are explictly declared.In this case, since it's declared in a string form, it's webpack instead of
@docusaurus/core
that will resolve this module to an absolute path. Sincewebpack
doesn't declare@babel/plugin-transform-runtime
as dependency, the resolution failed. By usingrequire.resolve
, we ensure that@docusaurus/core
will resolve the path. Since@docusaurus/core
declared@babel/plugin-transform-runtime
as a dependency, the resolution will succeed and results in a correct absolute path for webpack to consume.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)
I have setup a repo to show that these are the minimal changes necessary to make docusaurus work under
pnpMode: loose
.Also, all the tests still passes and deploy preview still works.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)