bun icon indicating copy to clipboard operation
bun copied to clipboard

Support NestJS

Open Jarred-Sumner opened this issue 1 year ago • 14 comments

This is a tracking issue to get bun's node.js compatibility far enough along to support https://nestjs.com/

Jarred-Sumner avatar Dec 21 '22 22:12 Jarred-Sumner

+1, It would be amazing if Bun would work with NestJS.

DavidFencl avatar Jan 20 '23 10:01 DavidFencl

+1, also would love this

kenerwin88 avatar Jan 21 '23 23:01 kenerwin88

+10 please !

jmls avatar Jan 23 '23 23:01 jmls

yes please!

michaelangeloio avatar Jan 25 '23 00:01 michaelangeloio

this would be a game changer

michaelangeloio avatar Jan 25 '23 00:01 michaelangeloio

+1 would be extremely interesting !!

MarcStdt avatar Feb 08 '23 20:02 MarcStdt

Where I can start to contribute on this issue?

muhad-bk avatar Feb 10 '23 15:02 muhad-bk

@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

ThatOneBro avatar Feb 10 '23 16:02 ThatOneBro

AFAIK NestJS relies on repl and the net module. At least these two I still see marked as open in the bun roadmap.

MarcStdt avatar Feb 10 '23 20:02 MarcStdt

I actually was very curious about this and just got bun up and running with a fresh install of nestjs. Am toying around with a basic API, I can update as things go to see what breaks.

ammanley avatar Feb 12 '23 08:02 ammanley

I actually was very curious about this and just got bun up and running with a fresh install of nestjs. Am toying around with a basic API, I can update as things go to see what breaks.

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.

piosystems avatar Feb 12 '23 12:02 piosystems

I actually was very curious about this and just got bun up and running with a fresh install of nestjs. Am toying around with a basic API, I can update as things go to see what breaks.

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.

piosystems avatar Feb 12 '23 12:02 piosystems

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

Jarred-Sumner avatar Feb 12 '23 12:02 Jarred-Sumner

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?

piosystems avatar Feb 12 '23 14:02 piosystems

If you want to build and run your project with Bun, you can:

bun upgrade --canary

package.json:

"start:dev": "nest start --watch --exec \"bun run\"",

nest-cli.json :

"entryFile": "main.js"

(bun didn't like being passed a script without a file extension)

devongermano avatar Mar 02 '23 04:03 devongermano

@devongermano it worked quite well using nest start --watch --exec \"bun run\" but when running

bun dist/main.js

it return http2 error ( i think its related to my project package somwhere)

Cannot find package "http2" from "/myprojectdir/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http2-handler.js"

mlazuardy avatar Mar 08 '23 14:03 mlazuardy

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.

krisanalfa avatar Mar 10 '23 08:03 krisanalfa

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

ntheanh201 avatar Mar 21 '23 07:03 ntheanh201

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.

DavidFencl avatar Mar 21 '23 07:03 DavidFencl

wait

fangzq229 avatar Apr 03 '23 09:04 fangzq229

Hi folks, what do we need to make the bun compatible with nestjs?

ghost avatar Apr 04 '23 22:04 ghost

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.

This week, I will try using prisma and i'll bring my feedback about it.

oishiimendesu avatar Apr 14 '23 23:04 oishiimendesu

hope nestjs support natively for bun runtime.

minhaics avatar Apr 20 '23 01:04 minhaics

Please put in in a bun!

ali-habibzadeh avatar May 17 '23 15:05 ali-habibzadeh

Has anyone done a test with version 0.6?

gabriiels avatar May 21 '23 19:05 gabriiels

Has anyone done a test with version 0.6?

doing this now, 0.6.3 // canary

elix1er avatar May 23 '23 22:05 elix1er

When running nest start --watch --exec \"bun run\"

it return missing script /dir/dist/main

does bun / nestjs need to explicitly use file type (js,ts) ?

mlazuardy avatar May 24 '23 14:05 mlazuardy

I have tested this in 0.6.3 and I see Bun appears to be having a problem setting the emitDecoratorMetadata setting. Injected services are undefined in the controller.

Anyone have any ideas on what we can do?

[Nest] 8956  - 05/25/2023, 7:10:01 AM   ERROR [ExceptionsHandler] undefined is not an object (evaluating 'this.appService.getHello')
getHello@/Users/austin/Documents/practice/bun-quickstart/src/app.controller.ts:12:57

tronicboy1 avatar May 24 '23 22:05 tronicboy1

I also experience some issues with decorators metadata on version 0.6.5 (1388ec0).

Importing reflect-metadata does not work, as detailed on issue https://github.com/oven-sh/bun/issues/2979.
This issue is probably a good starting point to improve the compatibility of Bun with frameworks such as NestJS.


Example

import 'reflect-metadata';

import { container, injectable } from 'tsyringe';

@injectable()
class Dependency {
  constructor() {
    console.log('Someone needs me!');
  }
}

@injectable()
class Service {
  constructor(dependency: Dependency)
  {
    console.log('I am the service and this is the dependency:', dependency);
  }
}

container.resolve(Service);

Edit It now seems to work on 0.6.5 (https://github.com/oven-sh/bun/commit/756e15f6e283fd7e21fe91e060d63440ce5c72de), thanks!

adrienbrignon avatar May 28 '23 12:05 adrienbrignon

It doesn't work for me, even with Canary

nest start --watch --exec \"bun run\"

bin/bash: nest: command not found

error: script "start:bun" exited with code 127

gtamas avatar May 31 '23 06:05 gtamas