Skip to content
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 AdonisJS 6 #4822

Open
4 of 6 tasks
RomainLanz opened this issue Sep 10, 2023 · 62 comments
Open
4 of 6 tasks

Support AdonisJS 6 #4822

RomainLanz opened this issue Sep 10, 2023 · 62 comments
Labels
enhancement New feature or request

Comments

@RomainLanz
Copy link

RomainLanz commented Sep 10, 2023

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

@RomainLanz
Copy link
Author

Current AdonisJS 6 fails to run because of Intl.ListFormat not yet available.

Tracking: #808

@RomainLanz RomainLanz changed the title Support AdonisJS 5 & 6 Support AdonisJS 6 Sep 10, 2023
@fareeda0
Copy link

Running on Linux (#1843 (comment)) seems to get a bit further.

Ace seems to run, and can run some commands.

However, server is still not running (error: expected ":" separator.)

Running ace:

Screenshot 2023-09-11 at 08 18 02

Running ace commands:

Screenshot 2023-09-11 at 08 19 37

Running server (doesn't work):

Screenshot 2023-09-11 at 08 20 16

@RomainLanz
Copy link
Author

RomainLanz commented Sep 16, 2023

The Intl.ListFormat issue has been fixed in the latest canary release of Bun.

bun upgrade --canary

Now running the ace command line breaks directly with the error error: expected ":" separator.

Running directly the server.ts script ends up with a similar error.

bun bin/server.ts
[0.78ms] ".env"
221 |   const callback = args[args.length - 1];
222 |   if (typeof callback !== "function")
223 |     @throwTypeError("Callback must be a function");
224 |   fs.readdir(...args).then((result) => callback(null, result), callback);
225 | 
226 | }, readFile = function readFile2(...args) {
                                                                   ^
TypeError: Invalid path string: can't be empty
 code: "ERR_INVALID_ARG_TYPE"

      at readFile2 (node:fs:226:64)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:60:6
      at new Promise (:1:20)
      at _getFrameSource (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:59:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:95:17
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:91:31
      at map (:1:20)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:91:8
      at new Promise (:1:20)
      at _parseError (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:88:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:323:6
      at new Promise (:1:20)
      at toJSON (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:322:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/core/build/index.js:33:38
      at processTicksAndRejections (:55:76)

It seems to be linked to an issue of Bun not sending back a file path when parsing the stack trace (using stacktracey). poppinss/youch#49

This is maybe due to Bun having a different format to display stack trace. https://github.com/xpl/stacktracey/blob/master/stacktracey.js#L49 - #185

@RomainLanz
Copy link
Author

Monkey patching the Youch module in the meanwhile end up with an issue to resolve the router from the IoC Container.

bun bin/server.ts
[1.13ms] ".env"

   TypeError: undefined is not an object (evaluating 'router.get')

This is probably due to a different way of initializing ESM modules.

The code that is breaking is:

import router from '@adonisjs/core/services/router'

router.get('/', async () => 'It works!')

The router instance is instantiated with the following.

import app from './app.js';
let router;

/**
 * Returns a singleton instance of the router class from
 * the container
 */
await app.booted(async () => {
    router = await app.container.make('router');
});

export { router as default };

@RomainLanz
Copy link
Author

RomainLanz commented Sep 16, 2023

It also appears to randomly fail on some pino transport mechanisms.

bun bin/server.ts
[0.20ms] ".env"

   TypeError: undefined is not an object (evaluating 'callers')
   
   
   ⁃ fixTarget
     node_modules/pino/lib/transport.js:129
   ⁃ <anonymous>
     node_modules/pino/lib/transport.js:93
   ⁃ transport
     node_modules/pino/lib/transport.js:90

The pino module does not run the same on Node.js and Bun.

function transport (fullOptions) {
  const { pipeline, targets, levels, dedupe, options = {}, worker = {}, caller = getCallers() } = fullOptions

  // Backwards compatibility
  const callers = typeof caller === 'string' ? [caller] : caller
  console.log(callers)
  
  // ...

Bun outputs undefined whereas Node.js outputs:

[
  'file:///Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/logger/build/src/pino.js',
  'file:///Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/logger/build/src/logger.js',
  'file:///Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/logger/build/src/logger_manager.js',
  'file:///Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/core/build/providers/app_provider.js'
]

Tracking: #4280

@capaj
Copy link
Contributor

capaj commented Sep 16, 2023

@RomainLanz see the latest comment in #4280, with a small hackfix pino runs nicely in bun

@RomainLanz
Copy link
Author

RomainLanz commented Sep 16, 2023

@RomainLanz see the latest comment in #4280, with a small hackfix pino runs nicely in bun

This fixed it, but yeah, it is a hack fix since having an if (global.bun) is not the way to go. 😄

I still have some random ESM loading issues (see #4822 (comment))

bun bin/server.ts
[1.70ms] ".env"
[0.00ms] ".env"

   TypeError: undefined is not an object (evaluating 'router.get')
 
   at module code start/routes.ts:2
   1|  /*
 ❯ 2|  |--------------------------------------------------------------------------
   3|  | Routes file
   4|  |--------------------------------------------------------------------------
   5|  |
   6|  | The routes file is used for defining the HTTP routes.
   7|  |

But running it another time seems to be good for the core of the framework!

bun bin/server.ts
[0.71ms] ".env"
[0.00ms] ".env"
[11:38:34.865] INFO (81972): started HTTP server on localhost:3333

CleanShot 2023-09-16 at 11 39 41@2x

@coratgerl
Copy link
Contributor

coratgerl commented Sep 17, 2023

The Intl.ListFormat issue has been fixed in the latest canary release of Bun.

bun upgrade --canary

Now running the ace command line breaks directly with the error error: expected ":" separator.

Running directly the server.ts script ends up with a similar error.

bun bin/server.ts
[0.78ms] ".env"
221 |   const callback = args[args.length - 1];
222 |   if (typeof callback !== "function")
223 |     @throwTypeError("Callback must be a function");
224 |   fs.readdir(...args).then((result) => callback(null, result), callback);
225 | 
226 | }, readFile = function readFile2(...args) {
                                                                   ^
TypeError: Invalid path string: can't be empty
 code: "ERR_INVALID_ARG_TYPE"

      at readFile2 (node:fs:226:64)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:60:6
      at new Promise (:1:20)
      at _getFrameSource (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:59:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:95:17
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:91:31
      at map (:1:20)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:91:8
      at new Promise (:1:20)
      at _parseError (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:88:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:323:6
      at new Promise (:1:20)
      at toJSON (/Users/romainlanz/workspace/lab/bun-test/node_modules/youch/src/Youch.js:322:11)
      at /Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/core/build/index.js:33:38
      at processTicksAndRejections (:55:76)

It seems to be linked to an issue of Bun not sending back a file path when parsing the stack trace (using stacktracey). poppinss/youch#49

This is maybe due to Bun having a different format to display stack trace. https://github.com/xpl/stacktracey/blob/master/stacktracey.js#L49 - #185

This bug is fixed in #4693

@jaspersmitNL
Copy link

jaspersmitNL commented Sep 18, 2023

I'm unable to to start it up, even using the bun canary build

  1. git clone https://github.com/adonisjs/slim-starter-kit
  2. cd slim-starter-kit
  3. bun install
  4. cp .env.example .env
  5. bun bin/server.ts
bun bin/server.ts   
[0.06ms] ".env"

   TypeError: undefined is not an object (evaluating 'callers')
 

   ⁃ fixTarget
     node_modules/pino/lib/transport.js:129
   ⁃ <anonymous>
     node_modules/pino/lib/transport.js:93
   ⁃ transport
     node_modules/pino/lib/transport.js:90

@RomainLanz
Copy link
Author

I'm unable to to start it up, even using the bun canary build

1. git clone https://github.com/adonisjs/slim-starter-kit

2. cd slim-starter-kit

3. bun install

4. cp .env.example .env

5. bun bin/server.ts
bun bin/server.ts   
[0.06ms] ".env"

   TypeError: undefined is not an object (evaluating 'callers')
 

   ⁃ fixTarget
     node_modules/pino/lib/transport.js:129
   ⁃ <anonymous>
     node_modules/pino/lib/transport.js:93
   ⁃ transport
     node_modules/pino/lib/transport.js:90

Yes, it still does not work well with pino.
You can monkey patch your node_modules to make it work.

Please, look at the latest comment of #4280 (comment).

@deevus
Copy link

deevus commented Oct 1, 2023

I'm unable to to start it up, even using the bun canary build

1. git clone https://github.com/adonisjs/slim-starter-kit

2. cd slim-starter-kit

3. bun install

4. cp .env.example .env

5. bun bin/server.ts
bun bin/server.ts   
[0.06ms] ".env"

   TypeError: undefined is not an object (evaluating 'callers')
 

   ⁃ fixTarget
     node_modules/pino/lib/transport.js:129
   ⁃ <anonymous>
     node_modules/pino/lib/transport.js:93
   ⁃ transport
     node_modules/pino/lib/transport.js:90

Yes, it still does not work well with pino. You can monkey patch your node_modules to make it work.

Please, look at the latest comment of #4280 (comment).

Just attempted with latest version of bun (1.0.3)

➜ bun bin/server.ts 
[11:48:06.838] INFO (191609): started HTTP server on localhost:3333

I get the message "It works!" in the browser.

@RomainLanz
Copy link
Author

RomainLanz commented Oct 20, 2023

With version 1.0.6 of Bun, we can run an AdonisJS Slim boilerplate with some issues loading ESM module with TLA.

bun bin/server.ts

   TypeError: undefined is not an object (evaluating 'router.get')

   at module code start/routes.ts:13
    8|   */
    9|
   10|  import HellosController from '#controllers/hellos_controller'
   11|  import router from '@adonisjs/core/services/router'
   12|
 ❯ 13|  router.get('/', async () => 'It works!')
   14|  router.get('/hello', [HellosController, 'greet'])
   15|

router is undefined but should not be. It is a flaky behavior.

We cannot run the ace file directly, but running the server works with bun bin/server.ts.

bun ace.js serve --watch
error: expected ":" separator

--

Trying out Dependency Injection, Bun seems not to emit metadata, making it unusable.

import { inject } from '@adonisjs/core';
import HelloService from '#services/hello_service';

@inject()
export default class HellosController {
  constructor(private helloService: HelloService) { }

  greet() {
    return this.helloService.hello('world');
  }
}

This is causing the code to fail because HelloService is not kept.

bun bin/server.ts
[12:40:52.521] INFO (69034): started HTTP server on 0.0.0.0:3333
[12:41:04.535] ERROR (69034): Cannot construct "[class HellosController]" class. Container is not able to resolve its dependencies
    request_id: "tkkwx1bcn7h2ce96u0xkarzn"
    x-request-id: "tkkwx1bcn7h2ce96u0xkarzn"
    err: {
      "type": "RuntimeException",
      "message": "Cannot construct \"[class HellosController]\" class. Container is not able to resolve its dependencies",
      "stack":
          Error: Cannot construct "[class HellosController]" class. Container is not able to resolve its dependencies
              at new Exception (/Users/romainlanz/workspace/lab/bun-test/node_modules/@poppinss/utils/build/index.js:43:50)
              at new RuntimeException (:1:33)
              at createError (/Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/fold/build/index.js:293:36)
              at <anonymous> (/Users/romainlanz/workspace/lab/bun-test/node_modules/@adonisjs/fold/build/index.js:365:12)
              at asyncFunctionResume (native)
              at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
              at promiseReactionJob (native)
              at processTicksAndRejections (native)
      "name": "RuntimeException",
      "status": 500,
      "code": "E_RUNTIME_EXCEPTION"
    }

@fareeda0
Copy link

Trying out Dependency Injection, Bun seems not to emit metadata, making it unusable

Tried with version 1.0.7 and emit metadata works with a flattened tsconfig.json. Seems related to #6326.

Flaky TLA import issue is still there though.

@fareeda0
Copy link

Interestingly, if you add ./node_modules to the extends path it also works:

{
  "extends": "./node_modules/@adonisjs/tsconfig/tsconfig.app.json",
  "compilerOptions": {
    // 
  }
}

Look related to: #5277

@RomainLanz
Copy link
Author

The following commit will probably fix ESM loading issue: oven-sh/WebKit@00ae02e

@Electroid Electroid added the enhancement New feature or request label Oct 27, 2023
@RomainLanz
Copy link
Author

The next version of Bun should arrive next Tuesday.
It will probably fix the flaky behavior when loading ESM module using TLA.

@RomainLanz
Copy link
Author

With Bun 1.0.8, we still have flaky behavior when loading ESM module using TLA.

bun bin/server.ts

   TypeError: undefined is not an object (evaluating 'router.get')

   at module code start/routes.ts:13
    8|   */
    9|
   10|  import HellosController from '#controllers/hellos_controller'
   11|  import router from '@adonisjs/core/services/router'
   12|
 ❯ 13|  router.get('/', async () => 'It works!')
   14|  router.get('/hello', [HellosController, 'greet'])
   15|

@RomainLanz
Copy link
Author

Bun 1.0.11 still has the issue above.

@RomainLanz
Copy link
Author

Same with 1.0.12

@Banashek
Copy link

Tested today on WSL2 with the steps above and it seems to start up fine.

OS: Windows 10
WSL2 linux version: Linux DESKTOP-4B5CT4E 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Bun version: 1.0.13

image

image

@fareeda0
Copy link

It's a flaky behaviour. Run bun run bin/server.ts a few times and you'll see It will fail sometimes.

   TypeError: undefined is not an object (evaluating 'router.use')
 
   at module code start/kernel.ts:36
   31|  router.use([() => import('@adonisjs/core/bodyparser_middleware')])
   32|  
   33|  /**
   34|   * Named middleware collection must be explicitly assigned to
   35|   * the routes or the routes group.
 ❯ 36|   */
   37|  export const middleware = router.named({})
   38|  

Tested with bun 1.0.13

@Banashek
Copy link

Interesting, I wasn't able to reproduce:

image

What OS are you on?

@fareeda0
Copy link

macOS 14.1 (Sonoma)

@Banashek
Copy link

I just tested on macos 13.5.1 and also was unable to reproduce.

I'll test out using more features to see if I can reproduce later when I have some time.

@Banashek
Copy link

Cloned the web-starter-kit as well and tested:

image

Added in a dynamic bit to the template and the js script to see if it would build things and render out properly (still used node ace build to build since bun ace doesn't work immediately):

image

@RomainLanz
Copy link
Author

I can confirm that it is still not working on Bun 1.0.14.

bun ./bin/server.ts

   TypeError: undefined is not an object (evaluating 'router.get')

@Banashek Are you doing anything special to make it work?

I am on a macOS Sonoma 14.0.

@RomainLanz
Copy link
Author

I will check to create a proper issue with a reproduction so the Bun team can address the bug.

@mattkenefick
Copy link

mattkenefick commented Nov 28, 2023

I was getting mixed results with 1.0.14 and the slim clone. Here's a video of me commenting and uncommenting a line with mixed results. In the middle of the video, you'll see that I don't actually change anything but it fails twice, then works.

Seems like it's some sort of cache / build / signature issue perhaps.

When I first installed it and ran it, I received the same issue as @RomainLanz

   TypeError: undefined is not an object (evaluating 'router.get')

Which then turn into the issue you see in the video of:

   TypeError: undefined is not an object (evaluating 'router.use')

And then became a mixed bag of working / not working. I started commenting pieces how to see how far the app would get before an error, and that's when it worked / failed / worked again in both commented and uncommented scenarios.

Later in the video (0:53) there's another new error which is interesting because I'm not changing anything significant in how I'm testing it.

ReferenceError: Cannot access uninitialized variable.
Screen.Recording.2023-11-28.at.10.18.19.AM.mov.mp4

@RomainLanz
Copy link
Author

I still have the issue with 1.0.29 on macOS.

CleanShot 2024-03-04 at 08 32 24@2x

@RomainLanz
Copy link
Author

I tried Bun 1.1 with my Windows setup, and it seems to not support Node.js subpath imports.

PS C:\workspace\lab\bun-adonis> bun run .\bin\server.ts

   ResolveMessage: Cannot find module "#start/env" from "C:\workspace\lab\bun-adonis\bin\server.ts"

@RomainLanz
Copy link
Author

Tracking subpath import: #10001

@RomainLanz
Copy link
Author

RomainLanz commented Apr 5, 2024

Side note, it is still flacky on macOS with version 1.1.1 with the same error related to ESM loading. I wasn't able yet to create a minimal reproduction but I didn't really had the time to do so.

If anyone want to try it. 👍🏻

@genesiscz
Copy link

Tracking subpath import: #10001

Isn't the subpath import fixable by just doing the same imports in tsconfig.json?

BTW how did you get rid of the error: expected ":" separator message?

Any progress on this?

@RomainLanz
Copy link
Author

Isn't the subpath import fixable by just doing the same imports in tsconfig.json?

There is no need to replicate the imports in the tsconfig.json file. TypeScript already reads the package.json entry. It all depends on which version of TypeScript Bun uses.

BTW how did you get rid of the error: expected ":" separator message?

I am not running the code through ace but directly.

@genesiscz
Copy link

Isn't the subpath import fixable by just doing the same imports in tsconfig.json?

There is no need to replicate the imports in the tsconfig.json file. TypeScript already reads the package.json entry. It all depends on which version of TypeScript Bun uses.

BTW how did you get rid of the error: expected ":" separator message?

I am not running the code through ace but directly.

But if you want to run serve --watch, you have to at least run the console command somehow.

I got as far as trying NODE_DEBUG=chokidar:ts bun bin/console.ts serve --watch which points me to the error being in the

const parsedConfig = this.#ts.getParsedCommandLineOfConfigFile( line of chokidar-ts.

@RomainLanz
Copy link
Author

Yes, we have to troubleshoot further why Ace command do not work.

Also, we are soon releasing an HMR feature for our CLI, meaning you will not have to use --watch anymore!

@kaanrkaan
Copy link

kaanrkaan commented Apr 23, 2024

Another compatibility issue that I noticed was with the test

SyntaxError: Export named 'Recoverable' not found in module 'repl'.

   at (syntax error) SyntaxError: Export named 'Recoverable' not found in module 'repl'.

As bun.js doesn't implemented the node:repl unit tests doesn't work on the adonisjs6 with bun

ps. there is an experimental bun:repl package. However, Recoverable is not implemented in that package either

The workaround is disabling repl for the test environment (I don't know if it does break functionality)

on adonisrc.ts file edit the providers (starting from 27th line in the api-starter)

  providers: [
    () => import('@adonisjs/core/providers/app_provider'),
    () => import('@adonisjs/core/providers/hash_provider'),
    {
      file: () => import('@adonisjs/core/providers/repl_provider'),
      environment: ['repl'],
    },
    () => import('@adonisjs/core/providers/vinejs_provider'),
    () => import('@adonisjs/cors/cors_provider'),
    () => import('@adonisjs/lucid/database_provider'),
  ],

this resolves the repl not found issue as it disables the repl_provider for the test environment.

did a simple test of

import { test } from '@japa/runner'

function sum(a, b) {
  return a + b
}

test('add two numbers', ({ assert }) => {
  assert.equal(sum(2, 2), 4)
})

and can confirm that the jabba tests are now working

image

@genesiscz
Copy link

Yes, we have to troubleshoot further why Ace command do not work.

Also, we are soon releasing an HMR feature for our CLI, meaning you will not have to use --watch anymore!

I actually made some progress.

The error: expected ":" separator comes from bun when you pass "--loader=ts-node/esm" to the command itself:

bun --loader=ts-node/esm bin/console.ts serve --watch

Because the console command serve tries to run it with the loader, it fails. Unfortunatelly you can't just delete the loader even though Bun doesn't need it.

https://github.com/adonisjs/assembler/blob/develop/src/helpers.ts#L31

@kaanrkaan
Copy link

Yes, we have to troubleshoot further why Ace command do not work.
Also, we are soon releasing an HMR feature for our CLI, meaning you will not have to use --watch anymore!

I actually made some progress.

The error: expected ":" separator comes from bun when you pass "--loader=ts-node/esm" to the command itself:

bun --loader=ts-node/esm bin/console.ts serve --watch

Because the console command serve tries to run it with the loader, it fails. Unfortunatelly you can't just delete the loader even though Bun doesn't need it.

https://github.com/adonisjs/assembler/blob/develop/src/helpers.ts#L31

Can't we use simple if statement like this to bypass the loader when run via bun?

if (process.versions.bun) {
  // this code will only run when the file is run with Bun
}

@RomainLanz
Copy link
Author

Yes, we have to troubleshoot further why Ace command do not work.
Also, we are soon releasing an HMR feature for our CLI, meaning you will not have to use --watch anymore!

I actually made some progress.
The error: expected ":" separator comes from bun when you pass "--loader=ts-node/esm" to the command itself:
bun --loader=ts-node/esm bin/console.ts serve --watch
Because the console command serve tries to run it with the loader, it fails. Unfortunatelly you can't just delete the loader even though Bun doesn't need it.
https://github.com/adonisjs/assembler/blob/develop/src/helpers.ts#L31

Can't we use simple if statement like this to bypass the loader when run via bun?

if (process.versions.bun) {
  // this code will only run when the file is run with Bun
}

Nope. Bun should support Node.js code as per their claim. We don't want to patch the AdonisJS codebase to make it work on Bun; they should adapt.

@kaanrkaan
Copy link

Yes, we have to troubleshoot further why Ace command do not work.
Also, we are soon releasing an HMR feature for our CLI, meaning you will not have to use --watch anymore!

I actually made some progress.
The error: expected ":" separator comes from bun when you pass "--loader=ts-node/esm" to the command itself:
bun --loader=ts-node/esm bin/console.ts serve --watch
Because the console command serve tries to run it with the loader, it fails. Unfortunatelly you can't just delete the loader even though Bun doesn't need it.
https://github.com/adonisjs/assembler/blob/develop/src/helpers.ts#L31

Can't we use simple if statement like this to bypass the loader when run via bun?

if (process.versions.bun) {
  // this code will only run when the file is run with Bun
}

Nope. Bun should support Node.js code as per their claim. We don't want to patch the AdonisJS codebase to make it work on Bun; they should adapt.

that makes sense 👍🏻 , meanwhile using the native watcher of the bun seems to do the job well

@RomainLanz
Copy link
Author

There are still some inconsistencies with Bun 1.1.9.

$ bun bin/server.ts
[12:05:46.878] INFO (74722): started HTTP server on 0.0.0.0:3333
^C⏎   

$ bun bin/server.ts

   TypeError: undefined is not an object (evaluating 'router.get')

   at module code start/routes.ts:13
    8|   */
    9|
   10|  import HellosController from '#controllers/hellos_controller'
   11|  import router from '@adonisjs/core/services/router'
   12|
 ❯ 13|  router.get('/', async () => 'It works!')
   14|  router.get('/hello', [HellosController, 'greet'])
   15|

@a4arpon
Copy link

a4arpon commented Jul 2, 2024

Any progress about it? I mean supporting adonis on Bun?

@necessarylion
Copy link

MacOS with bun --version 1.1.22

Still have issue

  $ bun bin/server.ts --watch

   TypeError: undefined is not an object (evaluating 'router.use')
 
   at module code start/kernel.ts:35
   30|  
   31|  /**
   32|   * The router middleware stack runs middleware on all the HTTP
   33|   * requests with a registered route.
   34|   */
  35|  router.use([() => import('@adonisjs/core/bodyparser_middleware'), () => import('@adonisjs/auth/initialize_auth_middleware')])
   36|  
   37|  /**
   38|   * Named middleware collection must be explicitly assigned to
   39|   * the routes or the routes group.
   40|   */

@dennis9779
Copy link

Still have issue 1.1.26

image

@ggaabe
Copy link

ggaabe commented Sep 6, 2024

on ubuntu with bun, trying to build the adonis project, I get this:

bun run build
$ node ace build
1 | (function (entry, fetcher)
    ^
SyntaxError: Export named 'register' not found in module 'module'.

Bun v1.1.26 (Linux x64)
error: script "build" exited with code 1

@ashokkumar88
Copy link

ashokkumar88 commented Sep 23, 2024

I am getting the below error when running bun bin/server.ts

ResolveMessage: Cannot find module "#start/env" from "/slim-starter-kit/bin/server.ts"

@httzipdev
Copy link

Is there any update on this?

@RomainLanz
Copy link
Author

There appears to be a regression in Bun 1.1.33. It fails to resolve files imported using Node's subpath imports.

❯ bun bin/server.ts

   ResolveMessage: Cannot find module '#start/env' from '/home/romain/workspace/lab/bun-test/bin/server.ts'

@ildfreelancer
Copy link

@RomainLanz sorry to ping you, do you know when this is resolved and supported?
Recently I am interested in using AdonisJS for my hobby project with bun, so I want to help in case we have some clues/hints to unlock us.

@RomainLanz
Copy link
Author

@ildfreelancer, I recommend reaching out to the Bun team for updates, as we are not currently working on making AdonisJS compatible with Bun. The compatibility issues are on Bun's side, not AdonisJS.

In the meantime, we suggest using Node.js to try AdonisJS, as the Bun team continues addressing their issues.

@RomainLanz
Copy link
Author

I may have good news. I have changed a bit the default boilerplate of an AdonisJS application to make it work with node --experimental-transform-types and it was working well.

After @jaredpalmer answer on this topic, I have tried to run the project using Bun, and it works!

Image

I will do more testing and do some benchmark!

@RomainLanz
Copy link
Author

RomainLanz commented Dec 2, 2024

After additional testing, I still occasionally encounter the issue mentioned earlier. I suspect this might be related to peer dependency resolution, but I'm not certain.

Image

When the server starts, it runs successfully, but Dependency Injection isn't functional yet (similar to the Node.js --experimental-transform-types runtime). This happens because we are relying on legacy decorators and TypeScript types, which are removed during compilation. Node.js uses SWC under the hood (not sure about Bun), which strips these features.

We'll need to wait for TypeScript to address this issue: microsoft/TypeScript#58101 / microsoft/TypeScript#57533 (comment)

Maybe #6326 is related too.

@RomainLanz
Copy link
Author

It looks like Bun 1.2 fixed the main issue we had to start our server!

Image

@RomainLanz
Copy link
Author

RomainLanz commented Jan 23, 2025

Here is a small benchmark of our Slim starter-kit with Bun and Node.js.

Using: autocannon -c 100 -d 40 -p 10

Bun 1.2

Running 40s test @ http://localhost:3333
100 connections with 10 pipelining factor


┌─────────┬───────┬───────┬───────┬───────┬──────────┬─────────┬───────┐
│ Stat    │ 2.5%  │ 50%   │ 97.5% │ 99%   │ Avg      │ Stdev   │ Max   │
├─────────┼───────┼───────┼───────┼───────┼──────────┼─────────┼───────┤
│ Latency │ 13 ms │ 29 ms │ 31 ms │ 32 ms │ 26.31 ms │ 5.82 ms │ 56 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴─────────┴───────┘
┌───────────┬─────────┬─────────┬────────┬─────────┬──────────┬─────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%    │ 97.5%   │ Avg      │ Stdev   │ Min     │
├───────────┼─────────┼─────────┼────────┼─────────┼──────────┼─────────┼─────────┤
│ Req/Sec   │ 35551   │ 35551   │ 37567  │ 37887   │ 37308.81 │ 587     │ 35544   │
├───────────┼─────────┼─────────┼────────┼─────────┼──────────┼─────────┼─────────┤
│ Bytes/Sec │ 5.87 MB │ 5.87 MB │ 6.2 MB │ 6.25 MB │ 6.16 MB  │ 96.7 kB │ 5.86 MB │
└───────────┴─────────┴─────────┴────────┴─────────┴──────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 40

1493k requests in 40.02s, 246 MB read

Node.js 22.13

Running 40s test @ http://localhost:3333
100 connections with 10 pipelining factor


┌─────────┬───────┬───────┬───────┬───────┬──────────┬─────────┬────────┐
│ Stat    │ 2.5%  │ 50%   │ 97.5% │ 99%   │ Avg      │ Stdev   │ Max    │
├─────────┼───────┼───────┼───────┼───────┼──────────┼─────────┼────────┤
│ Latency │ 12 ms │ 25 ms │ 29 ms │ 30 ms │ 21.69 ms │ 7.57 ms │ 483 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴─────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg     │ Stdev   │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec   │ 43743   │ 43743   │ 45183   │ 45407   │ 45065.6 │ 335.26  │ 43719   │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 9.27 MB │ 9.27 MB │ 9.58 MB │ 9.63 MB │ 9.55 MB │ 71.3 kB │ 9.27 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.
# of samples: 40

1804k requests in 40.02s, 382 MB read

@eokic
Copy link

eokic commented Jan 23, 2025

Wonder why fewer req/sec 🤔

@gaetandezeiraud
Copy link

Curious to know the overall memory consumption. The big difference may be there (or not).

@httzipdev
Copy link

Cool 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests