docusaurus: Minify failure when building docusaurus site in a yarn workspaces with another project
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 from 2.0.0-alpha.63, I have been unable to docusaurus build. I get this error:
(undefined) TypeError: Cannot read property 'replace' of undefined
at Object.options.minifyJS (main:18614:28)
at Object.chars (main:19102:24)
at main:48074:19
at String.replace (<anonymous>)
at new HTMLParser (main:48066:19)
at minify (main:18888:3)
at module.exports.exports.minify (main:19249:16)
at serverEntry_render (main:87861:38)
Error: Failed to compile with errors.
at /Users/treece/src/docusaurus-minify-troubles/node_modules/@docusaurus/core/lib/webpack/utils.js:164:24
at finalCallback (/Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/MultiCompiler.js:254:12)
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/MultiCompiler.js:277:6
at done (/Users/treece/src/docusaurus-minify-troubles/node_modules/neo-async/async.js:2931:13)
at runCompilers (/Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/MultiCompiler.js:181:48)
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/MultiCompiler.js:188:7
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/MultiCompiler.js:270:7
at finalCallback (/Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/Compiler.js:257:39)
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/Compiler.js:273:13
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/treece/src/docusaurus-minify-troubles/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:40:1)
at AsyncSeriesHook.lazyCompileHook (/Users/treece/src/docusaurus-minify-troubles/node_modules/tapable/lib/Hook.js:154:20)
at onCompiled (/Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/Compiler.js:271:21)
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/Compiler.js:681:15
at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/treece/src/docusaurus-minify-troubles/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
at AsyncSeriesHook.lazyCompileHook (/Users/treece/src/docusaurus-minify-troubles/node_modules/tapable/lib/Hook.js:154:20)
at /Users/treece/src/docusaurus-minify-troubles/node_modules/webpack/lib/Compiler.js:678:31
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
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 git@github.com:taylorreece/docusaurus-minify-troubles.gitcd docusaurus-minify-troublesyarn installcd docs/yarn build
If you remove other-project and then yarn install and yarn 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 46 (8 by maintainers)
Commits related to this issue
- fix(dinosaurdocs): do not hoist dependencies. Fixes issue where docs would not build in monorepo due to an html minifier issue https://github.com/facebook/docusaurus/issues/3515 — committed to Availity/availity-react by chrishavekost 4 years ago
- chore: 更新依赖避免 docusaurus 报错 https://github.com/facebook/docusaurus/issues/3515 — committed to alibaba/ali-react-table by feichao93 3 years ago
- chore: 更新依赖避免 docusaurus 报错 https://github.com/facebook/docusaurus/issues/3515 — committed to alibaba/ali-react-table by feichao93 3 years ago
- chore: 更新依赖避免 docusaurus 报错 https://github.com/facebook/docusaurus/issues/3515 — committed to alibaba/ali-react-table by feichao93 3 years ago
- chore: 更新依赖避免 docusaurus 报错 https://github.com/facebook/docusaurus/issues/3515 — committed to ljx94nb/ali-react-table by feichao93 3 years ago
- add nohoist fix from https://github.com/facebook/docusaurus/issues/3515 — committed to MaastrichtU-IDS/best-practices by vemonet 3 years ago
- add nohoist fix from https://github.com/facebook/docusaurus/issues/3515 — committed to MaastrichtU-IDS/best-practices by vemonet 3 years ago
- add nohoist fix from https://github.com/facebook/docusaurus/issues/3515 — committed to MaastrichtU-IDS/best-practices by vemonet 3 years ago
- add nohoist fix from https://github.com/facebook/docusaurus/issues/3515 — committed to MaastrichtU-IDS/best-practices by vemonet 3 years ago
- Trying to fix failing site deploy using "fix" from docusaurus issue https://github.com/facebook/docusaurus/issues/3515 — committed to kpmeen/kafka-websocket-proxy by kpmeen 3 years ago
- Attempt to fix build failure of developer docs This follows instructions from a Docusaurus Github issue to try and avoid a build failure caused by incompatibility of the alpha version of Docusaurus v... — committed to pupilfirst/pupilfirst by harigopal 2 years ago
I’ve fixed like this
resolutions: { “terser” : “4.8.0” }
I was able to make the repro repo build with the following:
Note: I’m not sure the “nohoist” config works with just
yarn install, had to regenerate the whole lockfile to make it work.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
html-minifier-terseras soon as it upgrades to Terser v5 so that this becomes a non-problem and we only use a single version of Terser.Temporary workaround: if you
nohoistthe docusaurus project, and remove allnode_modulesdirectories and runyarn installagain, the problem goes away. You do get duplicated directories in dependencies, as all of the docusaurus project’s dependencies are no longer shared, but that’s better than builds failing 🤷The latest Docusaurus betas shouldn’t have this problem anymore, no internal deps are using Terser 4 now
My deps tree using
@docusaurus/core@^2.0.0-alpha.66:Which gets resolved by Yarn into
node_modulesstructure:As it should be.
The only user of
terser@5is Docusaurus, which is also a user ofhtml-minifier-terserandhtml-webpack-plugin. Both of which use olderterser@4. Looks like Docusaurus gives a config interser@5format to those plugins as well, which fails with an error.Adding Yarn resolution to lower
terser-webpack-plugintemporary solves the issue:@slorber great sleuthing 😃 thanks so much…will hope to see the dependencies catch up
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
/packages/and my test site under/sites/, and the test site wouldn’t build after bumping up fromalpha.63. I finally managed to get anohoistconfig that seems to work but this feels like a very hacky solution, that only happens to work right now becausehtml-minifier-terseris a first-level dependency