-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Buffer Import Error When Building for Client-Side with Bun #8683
Comments
Can you share the exact command you are running? |
I'm trying to build a Vuetify/Vue 3 application:
I followed the examples from
Running the code in dev works without a problem. Edit: just updated to the latest version (1.0.29 (a146856)) and the issue still persists. I noticed the PR open for the problem, is there a workaround in the meantime? I'd love to stay on bun but if I can't make this work I'll have to switch to something else. |
Found a simple solution by installing the buffer package:
|
this did not work for me. Did you do anything else besides adding this package? thx! |
Yeah, it did not work for me either |
I have the following lines in my main.ts
and packages.json has the following dependency:
Haven't changed anything else. |
I've solved it by shoving |
just want to mention that I wrote a plugin that fixes this: const myPlugin: BunPlugin = {
name: "node buffer in the frontend",
setup(build) {
build.onResolve({ filter: /^buffer$/ }, (args) => {
const path_to_buffer_lib = path.resolve(
projectRoot(),
"node_modules/buffer/index.js"
);
if (path_to_buffer_lib)
return {
path: path_to_buffer_lib,
};
});
},
}; i also wrote a webframework for bun called mininext. It includes this plugin. |
I ran into this and this seems to work:
Notice the slash at the end? That's the way the Buffer maintainer recommends to import it, and seems to work here too. |
As recommended by the [Buffer maintainer](https://github.com/feross/buffer?tab=readme-ov-file#usage): >To require this module explicitly, use require('buffer/') which tells the node.js module lookup algorithm (also used by browserify) to use the npm module named buffer instead of the node.js core module named buffer! This solves a bug found bundling NSFWJS with Bun. ``` Build failed 1 | import { Buffer } from 'buffer'; ^ error: No matching export in "node:buffer" for import "Buffer" at [path] ``` More information: oven-sh/bun#8683
* Added trailing slash to Buffer import in index.ts As recommended by the [Buffer maintainer](https://github.com/feross/buffer?tab=readme-ov-file#usage): >To require this module explicitly, use require('buffer/') which tells the node.js module lookup algorithm (also used by browserify) to use the npm module named buffer instead of the node.js core module named buffer! This solves a bug found bundling NSFWJS with Bun. ``` Build failed 1 | import { Buffer } from 'buffer'; ^ error: No matching export in "node:buffer" for import "Buffer" at [path] ``` More information: oven-sh/bun#8683 * Add note about Bun issue --------- Co-authored-by: Jamon Holmgren <code@jamon.dev>
Thank you! This actually solves the problem. bun build ./index.tsx --outdir ./out --target browser (1) import { Buffer } from "buffer"; throws an error error: No matching export in "../../../../../bun-vfs$$/node_modules/buffer/index.js" for import "Buffer" (2) import { Buffer } from "buffer/"; just works [32ms] bundle 16 modules |
What version of Bun is running?
1.0.26+c75e768a6
What platform is your computer?
Darwin 23.2.0 arm64 arm
What steps can reproduce the bug?
import { Buffer } from "buffer"
in a Bun project configured for client-side code.What is the expected behavior?
Bun should correctly handle the import of Buffer from the buffer package, allowing the build process to complete successfully for client-side applications.
What do you see instead?
The build process fails with an error indicating that there is no matching export for the Buffer import.
Additional information
No response
The text was updated successfully, but these errors were encountered: