oven-sh / bun

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

nestjs failed to run `bun build main.ts --compile` #11836

Open joy-stacks opened 5 months ago

joy-stacks commented 5 months ago

What version of Bun is running?

1.1.13

What platform is your computer?

windows x64

What steps can reproduce the bug?

bun run src/main.ts success

image

but bun build src/main.ts --compile failed

image

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

A-D-E-A commented 5 months ago

NestJS uses optional/peer dependencies for many modules, such as "@nestjs/microservices" and "class-validator" in your example.

To efficiently compile, bun needs to bundle all modules required by the code, even the ones you don't actually use. Have you tried installing all these libraries before compiling? It may fix the problem in the meantime. You could also set all these dependencies as "external" in your build step I guess.

However, it would be nice to allow compilation with these unknown modules. Maybe with a flag like "--allow-missing-deps" or something? And it would also be nice to document this behavior.

joy-stacks commented 5 months ago

NestJS uses optional/peer dependencies for many modules, such as "@nestjs/microservices" and "class-validator" in your example.

To efficiently compile, bun needs to bundle all modules required by the code, even the ones you don't actually use. Have you tried installing all these libraries before compiling? It may fix the problem in the meantime. You could also set all these dependencies as "external" in your build step I guess.

However, it would be nice to allow compilation with these unknown modules. Maybe with a flag like "--allow-missing-deps" or something? And it would also be nice to document this behavior.

thanks

A-D-E-A commented 3 months ago

With v1.1.21 there's the new --packages=external flag. I didn't test it, but since the problem is due to optional dependencies, I bet it would solve the issue if it can be coupled with --compile.

Still, it would be nice to document that compilation with missing packages (add a warning about optional and peer dependencies, which are the most likely to trigger this) crashes. And that you have to either add the --packages=external flag, manually set the not-needed packages as externals, or install all of them.

I'm still rooting for an --allow-missing-deps flag of some sort, but that's probably just me.