Open yus-ham opened 1 year ago
this is a combination of #3426 (node:util) and #3205 (raw mode)
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
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"
I'm seeing the client.terminate is not a function
error in my custom webpack app as well when running the dev server.
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();
^
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?
I found this myself, and (seems like incorrectly) reported the bug in webpack https://github.com/webpack/webpack/issues/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();
^
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
? :thinking:
@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
(latest Bun v1.0.26)
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 ...
Thanks
bun --run run build
doesn't seem to work
bun --bun run docusaurus build
leads to the same error above:
If that helps, here's a more meaningful error message/stacktrace:
We are doing SSR/SSG using vm.Script
through this package: https://github.com/pierrec/node-eval
@slorber Got it, thanks for flagging that. We have some more work to do then
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:
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)
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: https://github.com/oven-sh/bun/issues/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.
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
Just tried v1.1 and Docusaurus still can't build.
I get an error due to unimplemented worker_thread
options (reported here: https://github.com/oven-sh/bun/issues/9816#issuecomment-2032631233) 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: https://github.com/oven-sh/bun/issues/3426#issuecomment-1929173528
It seems to work now for what it's worth. I had no issues with building with 1.1.22
.
Thanks
bun --run run build
doesn't seem to work
bun --bun run docusaurus build
leads to the same error above:If that helps, here's a more meaningful error message/stacktrace:
We are doing SSR/SSG using
vm.Script
through this package: https://github.com/pierrec/node-eval
I believe this is the same issue as: https://github.com/oven-sh/bun/issues/11539
I also see it working now, but we still need to use --no-minify
to avoid these errors:
[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.
When using that option, I'm able to build a newly initialized site with bun --bun run docusaurus build --no-minify
.
Surprisingly, it builds slower than Node 22.3:
hyperfine --runs 5 'yarn clear && yarn build --no-minify'
Benchmark 1: yarn clear && yarn build --no-minify
Time (mean ± σ): 7.716 s ± 0.080 s [User: 9.871 s, System: 2.259 s]
Range (min … max): 7.582 s … 7.793 s 5 runs
hyperfine --runs 5 'bun --bun run docusaurus clear && bun --bun run docusaurus build --no-minify'
Benchmark 1: bun --bun run docusaurus clear && bun --bun run docusaurus build --no-minify
Time (mean ± σ): 8.657 s ± 0.078 s [User: 12.067 s, System: 1.109 s]
Range (min … max): 8.584 s … 8.785 s 5 runs
bun new version 1.1.26 works.
use powershell
@abrahamcahyoadi
If anything, Bun v1.1.26 is a step back in my testing. It segfaults when running bun --bun run docusaurus clear && bun --bun run docusaurus build --no-minify
. Created #13584.
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?
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