-
-
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
Minify failure when building docusaurus site in a yarn workspaces with another project #3515
Comments
New info: one of my other projects has a dependency that has a dependency on If I have a project in my yarn workspaces with just that dependency, I can replicate this issue. I've updated my repro repo to show an extra project with just that dependency. Somehow that older version For my repro repo, I can build my docs project successfully if I add an explicit dependency to My stack trace references
file-loader version?
|
It seems to not be an issue with just |
Temporary workaround: if you
|
Hi, It seems it's not the webpack terserPlugin (that you can disable with the cli option) that is causing this problem, but rather the HTML minifier (not possible to disable atm). https://github.com/terser/html-minifier-terser It's worth checking with You could modify the "serverEntry.js" file locally to check what's happening and see if removing the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think I ran into the same issue. I get yarn why html-minifier-terser to be 5.1.1, with react-scripts contributing. Poking into the node_modules/@docusaurus/core/lib/client/serverEntry.js and removing minifyJS: true line did fix the build |
Note I have a monorepo setup also...I had considered taking the website out of the monorepo but curious if anything comes from this one |
Interesting. I'm also pinned to |
This is a pretty bad bug. I'm surprised the Docusaurus team has not run in to it, since they are also using a yarn workspace structure 🤔. I am also working in a monorepo, with a custom theme under {
"workspaces": {
"packages": [
"packages/*",
"sites/*"
],
"nohoist": [
"*/@docusaurus/*"
]
}
} |
Hi, Tried to hack a bit the repro from @taylorreece and found the issue: In Docusaurus core we run this static html files minification, which includes JS minification using the terser package. This html minify package calls terser: The problem is that terser.minify now returns a promise, and there's no "await", so this fails: I'm not sure to understand why adding/removing the file-loader dependency does affect which version of terser is used by this plugin, but in practice it does, and the html minification plugin ends up running an incompatible, newer version of terser, while it should stick to v4. We can see 2 different outputs according to the presence or not of the file-loader dependency in the other package: Not sure how it happens, but despite the |
Related to this issue: terser/html-minifier-terser#49 Also looks related to this Docusaurus upgrade: https://github.com/facebook/docusaurus/pull/3439/files |
I was able to make the repro repo build with the following:
Note: I'm not sure the "nohoist" config works with just Please let me know how this workaround works for you. I'm going to close this issue because I'm not sure we can do anything about it currently, really looks related to how Yarn install dependencies. We'll upgrade |
Hey @slorber - thanks a bunch for looking into this!
ended up working. I did not need regenerate a new |
Great to know 👍 Let me know if this workaround is not good enough, but I don't have anything better to propose for now ;) |
@slorber great sleuthing :) thanks so much...will hope to see the dependencies catch up |
…would not build in monorepo due to an html minifier issue facebook/docusaurus#3515
It worked for lerna config below. {
"packages": ["packages/*", "website"],
"version": "1.37.4",
"npmClient": "npm",
"hoist": true,
"nohoist": ["@docusaurus/*"]
} Just set the nohost for |
My deps tree using
Which gets resolved by Yarn into
As it should be. The only user of Adding Yarn resolution to lower {
"resolutions": {
"**/terser-webpack-plugin": "^1.4.3"
}
} |
I don't agree @the-spyke , If html-minifier-terser requires Terser 4, it should rather install a duplicate Terser4 package under html-minifier-terser node modules, which is not the case. As the 2 terser versions are incompatible, we should expect 2 versions to be used in practice. It is what actually happens in non-monorepos, or when you use nohoist, and what we actually want. Note: we upgraded Webpack terser plugin on purpose to upgrade a transitive dep having a security issue (https://github.com/facebook/docusaurus/pull/3439/files) |
Looks like yarn is doing everything right, but docusaurus is somehow introducing a broken, non-node module resolver. Why is docusaurus running html-minifier-terser with an alternative resolver? I am seeing that yarn is creating the correct
Here is the output when loaded via
And here is the output when loading
As you can see, yarn does the right thing but docusaurus -- or some sub-component of docusaurus -- somehow introduces buggy resolutions. @the-spyke is correct here. |
For anyone coming here because docusaurus logged an error message:
The only change is commenting out the following line, where docusaurus overrides module resolution behavior causing modules to receive incompatible dependency versions:
yarn, terser, and html-minify-terser are all behaving correctly. If docusaurus must override dependency resolutions, it'll need to be done in a way that doesn't violate version requirements. |
@cspotcode thanks for investigating. It looks like there's a reason for having this line and custom resolution: cf PR #1917 Removing it means potentially reintroducing an issue we had that was fixed, so not sure it is better. Do you have a suggestion on how to remove this line and still not have any regression on the issue this line fixed? |
I think that depends on which files require this custom resolution behavior. Webpack's default behavior is that files within |
@cspotcode unfortunately I don't know much more than you do, and I don't have a concrete solution to the problem you reported. If you have a solution to suggest that fits all use-cases nicely, is well-tested against a few existing monorepo Docusaurus sites (found in the related PRs) and does not trigger any regressionn, I'll be happy to review it. |
It sounds like it was only a problem with core-js, which as I understand is effectively a global singleton that applies changes to the browser environment, and preset-env was injecting This would tell webpack to resolve a version of core-js which matches the preset-env config, aka what the injected imports expect. It probably also makes sense to track this in an issue that's not closed. |
@cspotcode honestly I'm not sure to understand everything about this problem. The dev that implemented the resolution is not there anymore (https://docusaurus.io/blog/2020/01/07/tribute-to-endi) so I don't know much more than you do. If someone feels that this issue is important, wants to open an issue and document clearly what the problem is, creates a small monorepo repro, I'd be happy to look for a solution. Unless this issue becomes a problem for a larger number of users, I'd rather work on something else with a better ROI. I feel this issue looks like a time sink. It's hard to understand, hard to solve without risky side effects. It does not look like to affect a large number of users. There are good-enough workarounds (including overriding our internal |
As I look in docusaurus's code, I see some other dependency issues which have been avoided by running yarn 2 in loose mode. Would you like me to create a single issue listing everything I find? It may warrant splitting into sub-tickets, but a single issue is less spammy then creating multiples. |
I'm logging in this PR: pretty minor changes, but yarn e2es are passing without loose mode, and I'll enable all the other tests too. yarn 2 is intentionally strict so it should be a good way to validate that everything works, and that it's being done with vanilla dependency declarations instead of hacks. So the end result should be simpler behavior. |
Thanks, If things are not too related, multiple issues is better |
Not sure if this is helpful, but upgrading to 2.0.0-beta.0 fixed this issue for me. |
This is also the only solution from this issue which worked for me. |
Hey, I run into this issue with this environment:
This workaround has worked for me:
|
Hey, I still have this issue with Nx monorepo. I have documented the issue ZachJW34/nx-plus#181 I don't know yet if we can have a workaround in the docusaurus Nx builder (that's why I created the issue in their repo) or it have to be fixed here. thanks in advance for the help! |
Upgrading to |
Here a fix on yarn v2 if a developer has 2 versions of html-minifier-terser in the workspace My docusaurus version "resolutions": {
"@docusaurus/core/html-minifier-terser": "^6.0.2"
}, |
The latest Docusaurus betas shouldn't have this problem anymore, no internal deps are using Terser 4 now |
This follows instructions from a Docusaurus Github issue to try and avoid a build failure caused by incompatibility of the alpha version of Docusaurus v2 that we use with yarn. This issue is fixed in the latest (beta) version of Docusaurus, but its unusable because of its dependency on Webpack v5, which we do not support at the moment. See also: facebook/docusaurus#3515 (comment)
Edit from @slorber: TL.DR, try using this nohoist config
🐛 Bug Report
I have a Docusaurus-built site that shares a yarn.lock file with several other projects. Since bumping to Docusaurus to
2.0.0-alpha.64
from2.0.0-alpha.63
, I have been unable todocusaurus build
. I get this error:Have you read the Contributing Guidelines on issues?
Yes
To Reproduce
I've created a minimal repro repo, https://github.com/taylorreece/docusaurus-minify-troubles, with a new Docusaurus project created with
npx @docusaurus/init@next init docs classic
. I did not touch the docusaurus project otherwise.The other project in this repo, aptly named "other-project" has a package.json file with a series of dependencies.
These two projects share a
yarn.lock
.git clone [email protected]:taylorreece/docusaurus-minify-troubles.git
cd docusaurus-minify-troubles
yarn install
cd docs/
yarn build
If you remove
other-project
and thenyarn install
andyarn build
, the Docusaurus site builds fine.Expected behavior
I'd expect it to build.
Actual Behavior
I get the stack trace listed above
Your Environment
MacOS
Node v12.16.2
Yarn v1.22.4
The text was updated successfully, but these errors were encountered: