oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.16k stars 2.77k forks source link

Bun build `error: TODO: implement .node loader for Node.js target` #13198

Closed Araxeus closed 1 month ago

Araxeus commented 3 months ago

What version of Bun is running?

1.1.22-canary.96+df33f2b2a

What platform is your computer?

Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

create a file like so:

import { BitwardenClient } from '@bitwarden/sdk-napi';
const client = new BitwardenClient();

and try to build it via Bun.build or run bun build --target=node ./bw-test.ts

What is the expected behavior?

it builds

What do you see instead?

image

bun build --target=node ./bw-test.ts
error: TODO: implement .node loader for Node.js target

Additional information

this TODO: comment does not exist in this repo

https://github.com/search?q=repo%3Aoven-sh%2Fbun+%22TODO%3A+implement+.node%22&type=code

how is this possible? where is it coming from?

paperdave commented 3 months ago

this todo comment is defined in bundle_v2. quickly looking, it should be easily fixable by using e_require_call_target instead inlining import.meta.require(unique_key)

Araxeus commented 3 months ago

https://github.com/oven-sh/bun/blob/23aa4f295900eee60215022adc97c90e5dad9924/src/bundler/bundle_v2.zig#L2685

How come github search doesn't find it? I guess a bug with github? 🧐

Edit: seems like the file is just too big - it weighs 520kb and github search ignore files over 350kb

Probably a good idea to not have gigantic single files but you probably have your reasons

ikrom commented 1 month ago

what the solution of this bug? TODO: implement .node loader for Node.js target I'm trying build from my express app, then the error appear

regexj-twinkl commented 1 month ago

Also run into this error. Had to change to using esbuild. Problem was canvas is a native node module which bun attempts to bundle and throws this error. Could bun implement a solution similar to esbuild where you can add a parameter to list external packages so bun won't attempt to bundle them?

E.g.: external: ["canvas"],

See: https://esbuild.github.io/api/#external

Jarred-Sumner commented 1 month ago

@regexj-twinkl did you try external: ["canvas"] in bun?

regexj-twinkl commented 1 month ago

I did not. And I've just seen it's documented too. I must've missed that! I'll give it a try.

regexj-twinkl commented 1 month ago

Of course that works. No need for another builder. Thanks for the comment @Jarred-Sumner