Skip to content
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

Support Docusaurus #3426

Open
yus-ham opened this issue Jun 27, 2023 · 16 comments
Open

Support Docusaurus #3426

yus-ham opened this issue Jun 27, 2023 · 16 comments
Labels
bug Something isn't working

Comments

@yus-ham
Copy link
Contributor

yus-ham commented Jun 27, 2023

What version of Bun is running?

0.6.10

What platform is your computer?

ubuntu 22.04

What steps can reproduce the bug?

bunx --bun create-docusaurus@latest docusaurus

What is the expected behavior?

No response

What do you see instead?

image

found two bug here, one is the selection is not interactive, try using up, down key instead shows ^[[B^[[A
and another else the error in the bottom

Additional information

No response

@yus-ham yus-ham added the bug Something isn't working label Jun 27, 2023
@paperdave
Copy link
Collaborator

this is a combination of #3426 (node:util) and #3205 (raw mode)

@birkskyum
Copy link
Collaborator

birkskyum commented Aug 25, 2023

bunx --bun create-docusaurus@latest docusaurus is working in bun 0.8.1, but running start, build, serve with --bun all returns:

 9 |    }
10 | 
11 |    let seenVal = false;
12 | 
13 |    // Skip the first stack as it's this function
14 |    stacks.shift();
    ^
TypeError: stacks.shift is not a function. (In 'stacks.shift()', 'stacks.shift' is undefined)
      at /Users/admin/repos/docusaurus-test/docusaurus/node_modules/parent-module/index.js:14:1
      at /Users/admin/repos/docusaurus-test/docusaurus/node_modules/import-fresh/index.js:11:20
      at /Users/admin/repos/docusaurus-test/docusaurus/node_modules/@docusaurus/core/lib/server/config.js:36:10

Blocked by

@birkskyum
Copy link
Collaborator

With the stack.shift issue fixed, I now see this:

bun --bun run start:

TypeError: client.terminate is not a function. (In 'client.terminate()', 'client.terminate' is undefined)
      at /Users/admin/repos/docusaurus-test/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:70:12
      at forEach (:1:20)
      at /Users/admin/repos/docusaurus-test/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:64:6
65 |         /**
66 |          * @param {ClientConnection} client
67 |          */
68 |         (client) => {
69 |           if (client.isAlive === false) {
70 |             client.terminate();
                ^

bun --bun run build:

bun --bun run build


error: Cannot find module "/Users/admin/repos/docusaurus-test/docusaurus/build" from "bun:main"

@EvHaus
Copy link

EvHaus commented Nov 28, 2023

I'm seeing the client.terminate is not a function error in my custom webpack app as well when running the dev server.

@birkskyum
Copy link
Collaborator

I tried this with the new docusaurus 3.0.1, and while I still get these server errors, the localhost site does launch properly:

TypeError: client.ping is not a function. (In 'client.ping(() => {
          })', 'client.ping' is undefined)
      at /Users/admin/repos/bun-kitchensink/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:76:11
      at forEach (:1:21)
      at /Users/admin/repos/bun-kitchensink/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:64:7
65 |         /**
66 |          * @param {ClientConnection} client
67 |          */
68 |         (client) => {
69 |           if (client.isAlive === false) {
70 |             client.terminate();
                 ^
TypeError: client.terminate is not a function. (In 'client.terminate()', 'client.terminate' is undefined)
      at /Users/admin/repos/bun-kitchensink/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:70:13
      at forEach (:1:21)
      at /Users/admin/repos/bun-kitchensink/docusaurus/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:64:7
65 |         /**
66 |          * @param {ClientConnection} client
67 |          */
68 |         (client) => {
69 |           if (client.isAlive === false) {
70 |             client.terminate();
                 ^

@johnnyreilly
Copy link
Contributor

Does anyone know what the remaining issues are? It seems that some of the original linked issues have been fixed, we're still not in a working state - so is it not known what the remaining issues are?

@heysokam
Copy link

heysokam commented Jan 3, 2024

I found this myself, and (seems like incorrectly) reported the bug in webpack
webpack/webpack#17920

Then researched some more and landed on this issue
It seems to run for me, it just repeatedly spams this error in cli:

 Client
  Compiled successfully in 9.78s

client (webpack 5.89.0) compiled successfully
71 |
72 |             return;
73 |           }
74 |
75 |           client.isAlive = false;
76 |           client.ping(() => {});
               ^
TypeError: client.ping is not a function. (In 'client.ping(() => {
          })', 'client.ping' is undefined)
      at /ssd/dev/t/web/docutest/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:76:11
      at forEach (:1:21)
      at /ssd/dev/t/web/docutest/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:64:7
65 |         /**
66 |          * @param {ClientConnection} client
67 |          */
68 |         (client) => {
69 |           if (client.isAlive === false) {
70 |             client.terminate();
                 ^

@heysokam
Copy link

heysokam commented Jan 3, 2024

Found something else.
I did npm create docusaurus since I figured bun was the one bugging and causing problems.
But then I started docusaurus with bun start... and the above errors were not triggered.
So the current problem seems to be something related to bun create? 🤔

@slorber
Copy link

slorber commented Feb 5, 2024

@Electroid I'm the Docusaurus maintainer and don't know Bun much.
Can you detail how you run it exactly on a newly initialized site?

To me it looks like bun run build or bun run docusaurus build will actually use Node.js at runtime? 🤔

Logging process.version will notably log v20.11.0, my Node.js version, and I don't see any perf improvement, so I guess this is not the way to test Bun is able to run Docusaurus?

When I try bun run ./node_modules/.bin/docusaurus build I get errors

While the following works: node ./node_modules/.bin/docusaurus build

CleanShot 2024-02-05 at 23 07 49@2x

(latest Bun v1.0.26)

@birkskyum
Copy link
Collaborator

birkskyum commented Feb 5, 2024

To me it looks like bun run build or bun run docusaurus build will actually use Node.js at runtime? 🤔

You're right. You can force usage of bun with the --bun flag, like bun --bun run ...

@slorber
Copy link

slorber commented Feb 5, 2024

Thanks

bun --run run build doesn't seem to work

CleanShot 2024-02-05 at 23 21 00@2x

bun --bun run docusaurus build leads to the same error above:

CleanShot 2024-02-05 at 23 20 06@2x


If that helps, here's a more meaningful error message/stacktrace:

CleanShot 2024-02-05 at 23 25 26@2x

We are doing SSR/SSG using vm.Script through this package: https://github.com/pierrec/node-eval

@Electroid Electroid reopened this Feb 5, 2024
@Electroid
Copy link
Contributor

@slorber Got it, thanks for flagging that. We have some more work to do then

@slorber
Copy link

slorber commented Feb 6, 2024

Thanks for investigating @Electroid

I'm excited to see Bun support for Docusaurus happening 👍
We are not the fastest SSG tool out there so having an option to build a site much faster would be super useful to us.


Here's a minimal repro of the problem we encounter while rendering static pages of Docusaurus inside vm.Script:

https://github.com/slorber/bun-docusaurus-ssg-repro

const eval = require("eval");
const fs = require("fs");

async function run() {
    const fileContent = await fs.promises.readFile("server.bundle.js")
    console.log("fileContent",fileContent)

    const result = eval(
        fileContent,
        /* filename: */ "server.bundle.js",
        /* scope: */ {},
        /* includeGlobals: */ true
    )

    console.log("result",result)
}

run()

This runs in Node.js v20 but fails in Bun v1.0.26:

CleanShot 2024-02-06 at 10 58 23@2x

Of course server.bundle.js is a 10k LOC file built by Webpack so it's not "so minimal" 😅
But at least you do not have to deal with Docusaurus things to troubleshoot the problem.
I hope that helps.

Apart from that issue, it seems that otherwise the Docusaurus init template is able to run under Bun, so it's probably the only remaining problem 👍

(I still have another issue on our own Docusaurus website, but will have to investigate this independently)

@slorber
Copy link

slorber commented Feb 6, 2024

Apparently, the issue above is caused by this very old Node.js "require-like" lib:
https://github.com/felixge/node-require-like/blob/master/lib/require-like.js

Used internally in "node-eval", with pseudo-code such as:

const sandbox = {require: requireLike(_filename)}

vmScript.runInNewContext(sandbox,options)

https://github.com/pierrec/node-eval/blob/master/eval.js

I thought you'd find this useful, but I'll also try to see on my side if we can get rid of it.

Problematic code in that lib:

var Module = require('module');

Module._load(file, parentModule);

Related Bun bug: #5925


Edit: tried to replace this old require-like lib by Module.createRequire(). This time I was able to evaluate the script, but I now get another error while trying to build the Docusaurus init site 🤪

error: script "docusaurus" was terminated by signal SIGSEGV (Address boundary error)
zsh: segmentation fault  bun --bun run docusaurus build

This time I'm not sure how to troubleshoot that 😅

I also saw these warnings:

[bun] Warning: worker_threads.Worker option "eval" is not implemented.
[bun] Warning: worker_threads.Worker option "stdout" is not implemented.
[bun] Warning: worker_threads.Worker option "stderr" is not implemented.
[bun] Warning: worker_threads.Worker option "resourceLimits" is not implemented.

@161134077
Copy link

161134077 commented Mar 12, 2024

I have Problem, Install bun Docusaurus and bun start

Bun version 1.0.30

Error:

  Compiled successfully in 27.08s

client (webpack 5.90.3) compiled successfully
Watchpack Error (watcher): Error: AccessDenied
Watchpack Error (watcher): Error: AccessDenied

✔ Client
  Compiled successfully in 669.34ms

client (webpack 5.90.3) compiled successfully
71 |
72 |             return;
73 |           }
74 |
75 |           client.isAlive = false;
76 |           client.ping(() => {});
               ^
TypeError: client.ping is not a function. (In 'client.ping(() => {
          })', 'client.ping' is undefined)
      at /mnt/d/cobalg/docusaurus/docusaurusss/node_modules/@docusaurus/core/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:76:11
      at forEach (:1:21)
      at /mnt/d/cobalg/docusaurus/docusaurusss/node_modules/@docusaurus/core/node_modules/webpack-dev-server/lib/servers/WebsocketServer.js:64:7
error: script "start" exited with code 1

@slorber
Copy link

slorber commented Apr 2, 2024

Just tried v1.1 and Docusaurus still can't build.

I get an error due to unimplemented worker_thread options (reported here: #9816 (comment)) during the CSS/JS minification process.

Disabling modification gets me further until it segfaults during SSG:

yarn create docusaurus
bun --bun run docusaurus build --no-minify

Looks like it's still not working, similarly to my previous test here: #3426 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants