-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Support NestJS #1641
Comments
+1, It would be amazing if Bun would work with NestJS. |
+1, also would love this |
+10 please ! |
yes please! |
this would be a game changer |
+1 would be extremely interesting !! |
Where I can start to contribute on this issue? |
@muhad-bk We appreciate your enthusiasm! If you could try running a NestJS project in Bun and letting us know what breaks that would be extremely helpful. I'm not sure exactly sure what is missing for NestJS to work yet |
AFAIK NestJS relies on repl and the net module. |
I actually was very curious about this and just got |
I tried it too by using bun to run the distribution directly i.e. bun dist/main.js. It works for static routes. But application failed to start for more complex codes involving typeorm; concretely, a call to require('module').globalPaths along the line, erroneously returns "undefined" and aborts startup. |
To be more specific, the error was within app-root-path/lib/resolve.js in node_modules, called from typeorm. |
This error should be fixed once the canary builds (when CI is green) To upgrade: bun upgrade --canary |
The globalPaths issue has been fixed. Thank you. Next blocker is lack of http2 implementation by bun. Is http2 support roadmapped yet? |
If you want to build and run your project with Bun, you can:
package.json:
nest-cli.json :
(bun didn't like being passed a script without a file extension) |
@devongermano
it return http2 error ( i think its related to my project package somwhere)
|
I think Bun supports Nest.js. I made a simple repro repo here. Though it's a very minimal repo, but it's able to proof that it is possible to use Nest.js with Bun. |
I forked your repo and tried to integrate with Mongoose but it didn't work. I think we still need to wait quite a lot of time until we can use it in production |
My experience so far is same as @ntheanh201 says. Unless your app is super simple you will probably get compatibility issues with libs like Mongoose or TypeORM. |
wait |
Hi folks, what do we need to make the bun compatible with nestjs? |
This week, I will try using prisma and i'll bring my feedback about it. |
hope nestjs support natively for bun runtime. |
Please put in in a bun! |
Has anyone done a test with version 0.6? |
doing this now, 0.6.3 // canary |
When running it return missing script does bun / nestjs need to explicitly use file type (js,ts) ? |
I have tested this in 0.6.3 and I see Bun appears to be having a problem setting the Anyone have any ideas on what we can do?
|
@Jarred-Sumner You are doing amazing work. congrats 🎉. do you have plans to implement async_hooks? |
|
I just tried to migrate nestjs boilerplate to bun, but got warning and error.
|
With
@Get('/:my_route_param')
public index(
@Param('my_route_param') my_route_param: string
) {
// whatever
} Then when you run [Nest] 80972 - 12/23/2023, 11:53:24 PM LOG [NestFactory] Starting Nest application...
[Nest] 80972 - 12/23/2023, 11:53:24 PM LOG [InstanceLoader] AppModule dependencies initialized +20ms
9 | class ParameterMetadataAccessor {
10 | explore(instance, prototype, method) {
11 | const types = Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, method.name);
12 | const routeArgsMetadata = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, instance.constructor, method.name) || {};
13 | const parametersWithType = (0, lodash_1.mapValues)((0, reverse_object_keys_util_1.reverseObjectKeys)(routeArgsMetadata), (param) => ({
14 | type: types[param.index],
^
TypeError: undefined is not an object (evaluating 'types[param.index]') Here's the full example: import { Controller, Get, Module, Logger, Param } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
@Controller()
class AppController {
@Get('/:param')
public index (
@Param('param') param: string // <--- Still problematic.
) {
return {
message: 'Hello World!',
date: new Date(),
};
}
}
@Module({
controllers: [AppController],
})
class AppModule {}
async function main () {
const app = await NestFactory.create(AppModule);
const document = SwaggerModule.createDocument(app, new DocumentBuilder().build());
SwaggerModule.setup('docs', app, document);
await app.listen(3000);
Logger.log('Server started on http://localhost:3000', 'NestApplication');
}
main(); autogenerating swagger docs is super important if you want auto-generated type-safe clients with something like |
@iiian do you have |
That fixed it, nice! 🚢 🇮🇹 |
Anyone tried
|
@Jarred-Sumner I think this ticket should be re-opened, bun test doesn't work with a nestjs project and starting the project with the vscode debugger has the same result. In both cases it injects undefined dependencies. |
Nest + Bun work fine. I just tested my example repo at https://github.com/Scalahansolo/bun-nest and things still work well on bun 1.1 If your experiencing other issues, it's more likely an issue with some other lib. |
Thanks, interesting repo. It doesn't seem to contain any tests, which was what I mentioned. I'll clone it and see what the differences are with my solution. I'll also add the .vscode/launch to your repo and see if I get the same error as with bun test. I have gotten nest apis to work no problem, but specifically with running in debug mode and bun test I get undefined injectables. |
That may be true, but in that case I think a new issue to track that specific issue would be good. More noise here isn't going to help the bun team. |
It’s nor working with my basic boilerplate project
|
Basically bun does not seem to work with any serious (larger) NestJS Application since there are a lot of issues / bugs with decorators which are used a lot in NestJS (guards, controllers, interceptors, pipes, filters, swagger ....) and its dependencies (e.g. class-validator, class-transformer, mongoose, typeorm ...). It seems to boil down to issues/bugs with |
Turns out it's not noise. After lots of digging it was this open issue: #2927 I get the same undefined injectables with the dreaded 'Cannot access uninitialized variable' in nestjs. I think the decorator support is too buggy, but I can't find the exact line. So I think your statement 'Nest + Bun works fine' is a stretch. As I said earlier, your example repo is a really nice workspaces example though, so thanks, I copied some of it's approaches. |
The ask from Jarred is that we create new tickets for every problem with NestJS, to stay organized. I guess this ticket can still be linked, so it's easy to find things from here too, like this mentioned issue: |
I sure get that. The problem (for me) is that I don't have enough information for creating the ticket. I have a non-working nestjs app that sometimes fails with this error. Then it's better when I restart, it seems, and then sometimes not. The only useful data I have is the fact that it only happens in my nestjs apps, and nowhere else. So I'm not sure where to indicate it other than here. |
@GerbenRampaart , can you i.e. make a 'nest fails to run in bun' with repro steps, or mention that it's flaky in your case and crash frequency/type of app you have, and with your environment and what you see? |
Pushed all changes in my public repo and created this ticket: #10116 You should be able to reproduce by just cloning and running bun test. Other than that I haven't got a clue yet. |
Hey, here is the boilerplate which we are trying to adapt bun |
Probably may be because of cls-hooked, i have similar issue with bun/nest/typeorm/typeorm-transactional, if i use @transactional() decorator with bun i have this error:
|
If you try to run the project using bun, then it will start giving errors on interface files like they don't exist |
@kongxiangyiren @Jarred-Sumner Okay sorry I did not see the post which says that we should create new tickets for these issues. |
Is there an update on this? |
Has it been created? |
Please create new issues for the specific errors you're running into. We will fix them, but NestJS itself works in Bun. |
This is a tracking issue to get bun's node.js compatibility far enough along to support https://nestjs.com/
The text was updated successfully, but these errors were encountered: