This issue consists of two different problems that both prevent me from working with this library: https://github.com/ricky0123/vad
But the issues are not just for that library of course, I've had the first problem more often and I'm sure the second problem also happens in other libraries that require these type of dependencies.
It seems that whenever I'm building for dynamic imports await import(...) for target "browser" results in buildfiles in the wrong place and sometimes overwriting the original code. E.g. import("abc") results in overwriting node_modules/abc/index.js being overwritten.
I can't therefore do dynamic imports with React.lazy and thus it's impossible to import code that uses window in it.
Issue 2) Bun.build can't install perf_hooks / worker_threads from onnxruntime-web
With things like web pack it should be possible but with Bun.build target "browser" it seems to crash.
After resolving the window error(s), things like http://github.com/ricky0123/vad don't build due to the inability of Bun.build to build it with target browser.
error: Could not resolve Node.js builtin: "perf_hooks". To use Node.js builtins, set target to 'node' or 'bun' /Users/king/os/packages/ui-visual-smart/recording-audio/node_modules/vad/node_modules/onnxruntime-web/dist/ort-web.node.js:6:534820 534947
error 2: error: Could not resolve Node.js builtin: "worker_threads". To use Node.js builtins, set target to 'node' or 'bun' /Users/king/os/packages/ui-visual-smart/recording-audio/node_modules/vad/node_modules/onnxruntime-web/dist/ort-web.node.js
What version of Bun is running?
0.8.1
What platform is your computer?
Darwin 21.6.0 arm64 arm
What steps can reproduce the bug?
This issue consists of two different problems that both prevent me from working with this library: https://github.com/ricky0123/vad
But the issues are not just for that library of course, I've had the first problem more often and I'm sure the second problem also happens in other libraries that require these type of dependencies.
Issue 1)
Bun.build({ target: "browser" })
with dynamicimport()
s strange behaviourI'm doing React SSR using Bun by building all react code with target browser. I adapted this example: https://github.com/bun-community/create-templates/tree/main/react-ssr
Building works like this:
It seems that whenever I'm building for dynamic imports
await import(...)
for target "browser" results in buildfiles in the wrong place and sometimes overwriting the original code. E.g.import("abc")
results in overwritingnode_modules/abc/index.js
being overwritten.I can't therefore do dynamic imports with
React.lazy
and thus it's impossible to import code that useswindow
in it.This occurred to me when trying to install http://github.com/ricky0123/vad
Issue 2) Bun.build can't install perf_hooks / worker_threads from onnxruntime-web
With things like web pack it should be possible but with Bun.build target "browser" it seems to crash.
After resolving the window error(s), things like
http://github.com/ricky0123/vad
don't build due to the inability ofBun.build
to build it with target browser.error:
Could not resolve Node.js builtin: "perf_hooks". To use Node.js builtins, set target to 'node' or 'bun' /Users/king/os/packages/ui-visual-smart/recording-audio/node_modules/vad/node_modules/onnxruntime-web/dist/ort-web.node.js:6:534820 534947
error 2:
error: Could not resolve Node.js builtin: "worker_threads". To use Node.js builtins, set target to 'node' or 'bun' /Users/king/os/packages/ui-visual-smart/recording-audio/node_modules/vad/node_modules/onnxruntime-web/dist/ort-web.node.js
Library: https://github.com/Microsoft/onnxruntime
What is the expected behavior?
These things work like they do in webpack
What do you see instead?
Strange behaviour and crash when building
Additional information
To reproduce, just try and install https://github.com/ricky0123/vad in a React SSR setup like https://www.npmjs.com/package/@bun-examples/react-ssr