Repository navigation
Closed
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
I got the following error
[ERROR] Error: Command failed: ps cax -o command | grep -E "^(Google Chrome Canary|Google Chrome Dev|Google Chrome Beta|Google Chrome|Microsoft Edge|Brave Browser|Vivaldi|Chromium)$"
at genericNodeError (node:internal/errors:983:15)
at wrappedFn (node:internal/errors:537:14)
at ChildProcess.exithandler (node:child_process:414:12)
at ChildProcess.emit (node:events:524:28)
at maybeClose (node:internal/child_process:1101:16)
at Socket.<anonymous> (node:internal/child_process:456:11)
at Socket.emit (node:events:524:28)
at Pipe.<anonymous> (node:net:351:12) {
code: 1,
killed: false,
signal: null,
cmd: 'ps cax -o command | grep -E "^(Google Chrome Canary|Google Chrome Dev|Google Chrome Beta|Google Chrome|Microsoft Edge|Brave Browser|Vivaldi|Chromium)$"',
stdout: '',
stderr: ''
}
I don't have any of these browsers installed and I don't want to install any of them. I do have Safari on my Mac. Why don't you consider it as a suitable browser to open the Docusaurus?
Reproducible demo
No response
Steps to reproduce
Run npm run start on the computer where is only Safari or Firefox is installed.
Expected behavior
I can use my favorite browser.
Actual behavior
I got the error.
Your environment
- Docusaurus version used: 3.8.0
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Safari, Node 22.13
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOs
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
bugAn error in the Docusaurus core causing instability or issues with its execution
Activity
slorber commentedon May 27, 2025
Thanks for reporting, indeed, this is not expected to throw an error. You can bypass this with the
--no-openCLI option.We do consider Safari a suitable browser.
The code producing this bug is a special handling for Chromium-based browsers on macOS. We didn't write it, it comes from Create-React-App. Since it was unmaintained and had performance issues, we internalized that code, and fixed the sync call perf bottleneck in #11007
I don't know much about macOS / AppleScript, but this logic permits to "reuse" an existing localhost browser tab instead of opening a new one in Chrome. Maybe this is not possible to achieve for Safari? 🤷♂ We didn't write this part, just copy/pasted existing code.
IMHO, the problem is just my integration that now prints an error message instead of swallowing it. I believe the error is not critical (does not crash the dev server), and also, isn't Safari opening like before? (not 100% sure)
slorber commentedon May 27, 2025
No you are right this error is blocking, and will be fixed in #11205
Regarding doing the same as Chrome but for Safari (reusing the tab), I tried to port out AppleScript to work with Safari:
It almost work but it looks like it's only possible to focus the tab by default, and not reload it like we do in Chrome.
Unless the user configures their Safari DevTools accordingly to allow
do JavaScritto run.I'm not sure we can really implement the same for Safari with a good DX, afaik there's no alternative to reload the Safari tab, and it's hard to teach users to configure their devtools for a marginal DX improvement.
If anyone wants to work on this, please submit a PR, but I consider this quite low ROI.
package.json - Replace BROWSER=none with --no-open
slorber commentedon Jun 6, 2025
Fixed in latest release https://github.com/facebook/docusaurus/releases/tag/v3.8.1
ilg-ul commentedon Jul 15, 2025
There must be something wrong, I'm still getting this error on my Mac where I have no Chrome, even with the latest
canary-6366:If I manually patch
openBrowser.jsto skipawait execPromise(command).catch(() => {...}), it no longer crashes.It looks like the
catch()is not effective.slorber commentedon Jul 15, 2025
The error looks different; it seems that your computer can't spawn a child process for unknown reasons. Maybe this happens just for you, and not others, hard to know why.
ilg-ul commentedon Jul 15, 2025
Right, for one reason or another, my Mac can't spawn the
ps ...process, but I expectedcatch()to be triggered and recover from the error.I'll try to further investigate.
slorber commentedon Jul 15, 2025
It's possible that the library doesn't expect that from happening and is throwing the error synchronously instead of asynchronously.
Try adding a try/catch in addition to the
.catch()to see.That's also why we just got a new
Promise.try()feature in ES: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/tryilg-ul commentedon Jul 15, 2025
Yes, that's what I planned to do.
ilg-ul commentedon Jul 15, 2025
I first patched the local code in
openBrowser.jsto read:I saw the
[ERROR] Error: spawn EBADF...message reported before and none of my messages.Then I patched the code to read:
I saw the
catchandemptymessages.My JS knowledge is not deep enough to comment on the
await ... catch()code correctness, but since the classicaltry ... catchseems functional, I would use it.It would be even better to diagnose why the
execPromise()fails on macOS.slorber commentedon Jul 17, 2025
@ilg-ul the
execPromisedoesn't fail on macOS, it fails for you specifically, probably due to something fancy you have locally that others don't. It works perfectly fine for me and if others had a similar problem, they would have reported.docusaurus startis commonly run by many macOS devs.We can't easily troubleshoot this; it's standard Node.js code.
Maybe you can reproduce the problem outside of Docusaurus and report that as a Node.js issue:
Anyway, we'll add an extra try/catch since it fixes the problem, but I'd rather not swallow the error message since it may hide a problem you have on your computer, so it's still nice to be aware of it even if a console log message might be annoying.
ilg-ul commentedon Jul 17, 2025
I did the following test:
The first call prints the (long) list of processes.
The second fails with:
I took a long look at the error, but I can't tell what is wrong with it, the command runs just fine in a terminal.
From the documentation it results that a sub-shell is used, so the pipe should not be a problem.
I wonder what might be that fancy on my Mac to cause this?
ilg-ul commentedon Jul 17, 2025
Update:
The error is cause by
grepexiting with a non-zero.If I replace
ChromewithSafari, the code no longer fails, and prints several process names that includeSafari.slorber commentedon Jul 17, 2025
The error you now get is different from EBADF
Our source code contains the
-Eoption:grep -E, which you removed. It should return exit code 0 with that option, even if no process with that name could be found.ilg-ul commentedon Jul 17, 2025
With
-EI get the same error:As far as I know,
-Emeans extended regexp.slorber commentedon Jul 21, 2025
Ah yes, this is expected to fail actually, I added a comment in my source code:
I'm not sure grep has any built-in way to return 0 exit code, but using
|| truein the command probably works.Anyway, it looks like you are not able to reproduce your
[ERROR] Error: spawn EBADFinitial error anymore?Since we swallow the grep exit code 1, maybe your local problem is now fixed?
ilg-ul commentedon Jul 21, 2025
The point here is not the error itself, but the confusing thing that the
catch()does not actually catch the error and requires theexecPromise()to be surrounded by the safertry ... catch().As for the EBADF, it might be a temporary side effect of a previous build of the huge LLVM project, that probably tries to start too many parallel actions, depleting the system resources.
I think that regardless the size of the project, Docusaurus should limit the number of parallel actions to a reasonable value.
slorber commentedon Jul 24, 2025
The
.catch()does catch the error returned by grep.It only doesn't catch the EBADF error you got, which is different.
I'll add an extra try/catch for v3.9, but I doubt this issue affects a lot of people apart from you temporarily. #11347
We already do in various places, but probably not everywhere. What kind of "parallel actions" do you have in mind?
Why would a previous build affect
docusaurus startif your previous build is not running anymoreilg-ul commentedon Jul 24, 2025
Great, thank you!
I don't know the Docusaurus internals, but, according to my tests in other projects, the gain of running parallel actions that generate content in memory and then write it on disk is minimal with today very fast disks, but the memory consumption is linear with the number of actions. For the LLVM test project I reached more than 60 GB for 20K+ files, which is not reasonable. I'm convinced that if we could limit the number of parallel actions to some tens, the build would complete and the system would not trash.
Parallelising actions that do network accesses is obviously beneficial, but the benefits of parallelising actions that do accesses on fast SSDs are debatable.
slorber commentedon Jul 24, 2025
We can't avoid loading all the data into memory. We have plugin lifecycles that receive that data, and changing the public API contract would be a breaking change for our whole plugin ecosystem.
Also keep in mind that bundlers might have similar constraints: they need to load and see the whole module graph to bundle the final app.
We cannot create the Docusaurus site "incrementally" by reading files one by one and building slices of the site; we need to feed the engine everything at once and let it build. That's a constraint we have for modern frontend experience. Tools not based on client-side navigations like Eleventy/Hugo and others can probably provide an incremental mode because they do not have these constraints of building a frontend app.
At best, we could limit the parallelization when reading content files so that we don't read too many of them at once, but at the end of the day, we have to aggregate all the data we read in memory so that plugins and bundlers can see the whole picture.
ilg-ul commentedon Jul 24, 2025
I see.
The
doxygen2docusaurusconverter also requires everything in memory, so all input XMLs, data model objects, view model objects, etc are in RAM. For the LLVM project there are probably ~300.000 class member definitions present at once. But the conversion takes a few minutes and uses a few GB of RAM. For the same content, a Docusaurus build went to 60GB+ and, after hours, it got stuck.I can imagine Docusaurus doing a lot more, but perhaps some improvements in memory management would be useful.
slorber commentedon Jul 24, 2025
Perf and memory improvements have been the focus of my work for the past months, and I've kinda exhausted all the low-hanging fruits I could find. If you have any idea how to improve things, contributions are welcome, but we need a concrete POC with a visible impact and not vague ideas. Also, some of these improvements could come from other places, such as our bundler Rspack, which also works on optimizations.