Open RomainLanz opened 1 year ago
Current AdonisJS 6 fails to run because of Intl.ListFormat
not yet available.
Running on Linux (https://github.com/oven-sh/bun/issues/1843#issuecomment-1710732503) seems to get a bit further.
Ace seems to run, and can run some commands.
However, server is still not running (error: expected ":" separator
.)
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). https://github.com/poppinss/youch/pull/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 - https://github.com/oven-sh/bun/issues/185
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 };
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'
]
@RomainLanz see the latest comment in #4280, with a small hackfix pino runs nicely in bun
@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 https://github.com/oven-sh/bun/issues/4822#issuecomment-1722181339)
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
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
I'm unable to to start it up, even using the bun canary build
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
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 https://github.com/oven-sh/bun/issues/4280#issuecomment-1722188648.
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.
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"
}
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 https://github.com/oven-sh/bun/issues/6326.
Flaky TLA import issue is still there though.
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: https://github.com/oven-sh/bun/issues/5277
The following commit will probably fix ESM loading issue: https://github.com/oven-sh/WebKit/commit/00ae02e4c661357fd30a8153c58905eccc57be78
The next version of Bun should arrive next Tuesday. It will probably fix the flaky behavior when loading ESM module using TLA.
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|
Bun 1.0.11
still has the issue above.
Same with 1.0.12
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
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
Interesting, I wasn't able to reproduce:
What OS are you on?
macOS 14.1 (Sonoma)
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.
Cloned the web-starter-kit as well and tested:
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):
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.
I will check to create a proper issue with a reproduction so the Bun team can address the bug.
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.
https://github.com/oven-sh/bun/assets/149809/69b9e3fc-e001-4783-b1ab-ca0afbc7dba1
@RomainLanz Nothing to my knowledge:
Perhaps there's a chance packages are cached either on my side? I'll try again on a fresh computer when I get a chance.
@RomainLanz Nothing to my knowledge Perhaps there's a chance packages are cached either on my side? I'll try again on a fresh computer when I get a chance.
@Banashek
Try stopping, starting, stopping, starting, etc.
In my video above, I was able to produce both of your results with one install.
I still have the issue with the latest release (1.0.25
).
bun bin/server.ts
TypeError: undefined is not an object (evaluating 'router.get')
I have added some logs inside the router
resolution and it seems correct:
let router;
/**
* Returns a singleton instance of the router class from
* the container
*/
await app.booted(async () => {
console.log('booted')
console.log(await app.container.make('router'))
router = await app.container.make('router');
});
export { router as default }
bun bin/server.ts
booted
Router { .... }
TypeError: undefined is not an object (evaluating 'router.get')
--
I tried to create a minimal reproduction of the bug but it wasn't successful. It seems the bug is not directly linked to TLA, I will need to troubleshoot further.
// router.js
async function sleepThen(ms, callback) {
await new Promise(resolve => setTimeout(resolve, ms));
callback();
}
let router
await sleepThen(10, async () => {
router = { get() { console.log('working') }}
})
export default router
// app.js
import router from './router.js'
router.get()
bun app.js
// working
bun run bin/server.ts
is fully functional for me on the latest version (1.0.29) using the slim and api adonis templates. Tried it on wsl2 and docker.
I still have the issue with 1.0.29
on macOS.
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"
Tracking subpath import: https://github.com/oven-sh/bun/issues/10001
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. šš»
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?
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.
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 thepackage.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.
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!
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
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
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 theloader
, 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
}
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 commandserve
tries to run it with theloader
, 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#L31Can'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.
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 commandserve
tries to run it with theloader
, 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#L31Can'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
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|
Any progress about it? I mean supporting adonis on Bun?
MacOS with bun --version 1.1.22
Still have issue
ResolveMessage: Cannot find module "#start/env"
(Similar to #10001) and after changing the path to use directly , it got another errorā $ 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| */
Still have issue 1.1.26
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
This is a tracking issue to get bun's node.js compatibility far enough along to support https://adonisjs.com
Intl.ListFormat
#808