-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
error: No matching export in "node:buffer" for import "Buffer" #12272
Comments
In which version has hat been fixed? I still see exactly this behavior in version 1.1.33, released just 5 days ago. |
@CodingMarkus it wasn’t a bug, I just wasn’t including the right arguments to the build command. The default target is “browser” you need to pass an explicit “node” value to the target argument. |
But I'm seeing this issue with this Buffer implementation: https://github.com/feross/buffer And as the page says: "The buffer module from node.js, for the browser." When running
it downloads exactly this implementation and I can use it in TypeScript with
but I cannot use
As that yields exactly the same error. Note that the same project has no issue when I install the package with |
Hmm, I’m not sure. I wonder if it’s due to a difference in import precedence when the external package name matches a built in package name. Are you able to import using a relative path “./node_modules/path-to-package” instead of “buffer”? Does tsc default to browser also, or is tsc targeting a node bundle? |
There is no
|
@CodingMarkus hey, sorry i completely forgot to respond to this.
Scenario A import { Buffer } from "buffer";
Scenario B import { Buffer } from "./node_modules/buffer/index.js";
Scenario A outputs the error you're experiencing. Scenario B builds successfully. I'm assuming the node builtins are taking precedence over node_modules. To overcome you're issue, simply reference the library directly instead of using the default module resolution. I'm not sure what the correct resolution precedence is supposed to be, but both bun and node behave the same way in this scenario. Perhaps import { Buffer as thirdPartyBuffer } from "./node_modules/buffer/index.js";
console.log(thirdPartyBuffer === global.Buffer);
import { Buffer as maybeThirdPartyBuffer } from "buffer";
console.log(maybeThirdPartyBuffer === global.Buffer);
|
I'm currently experiencing this issue, and cannot reference buffer by relative path, because its being referenced inside of another library dependency. Please, any workaround I can apply to resolve this? |
What version of Bun is running?
1.1.17+bb66bba1b
What platform is your computer?
Darwin 23.2.0 arm64 arm
What steps can reproduce the bug?
While using bun to run a typescript file that, imports the
Buffer
named export from thenode:buffer
module, theBuffer
is imported. However, when usingbun build
on the same file:error: No matching export in "node:buffer" for import "Buffer"
index.ts
While trying to transpile:
> bun build index.ts
While executiong the TS directly:
> bun run index.ts
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: