-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 TypeORM #4136
Comments
Thanks for reporting, what's the error you run into? |
Sorry @Electroid, I submitted the issue by mistake before completely filling it out. I have updated the comment now. |
I'm not sure how far Bun will support the TS decorators stuff. You may be able to "compile" your app with I use Mikro-ORM and that's what I'm doing right now. |
@bnussman, may I know how you init const orm = await MikroORM.init<SqliteDriver>({
entities: ['./entities/**/*.ts'], // path to our JS entities (dist), relative to `baseDir`
entitiesTs: ['./entities/**/*.ts'], // path to our TS entities (source), relative to `baseDir`
}); |
Use JS for the const config: Options = {
entities: ['./build/entities/*.js'],
entitiesTs: ['./src/entities/*.ts'],
}; |
I think @dylan-conway will have an exciting update for you today |
OMG! Nevermind, seems like @Jarred-Sumner is here to save the day ❤️🚀 |
I was able to use Mikro-ORM by creating a plugin: import type { BunPlugin } from "bun";
import { readFile } from "fs/promises";
import strip from "strip-comments";
import { transpileModule, type TranspileOptions } from "typescript";
// fix this import based on your tsconfig location
import config from "../../tsconfig.json";
const theFinder = /((?<![(\s]\s*['"])@\w[.[\]\w\d]*\s*(?![;])[((?=\s)])/;
const findDecorators = (fileContent: string) => theFinder.test(strip(fileContent));
export const bunDecorators: BunPlugin = {
name: "bun-decorators",
setup: (build) => {
build.onLoad({ filter: /\.ts$/ }, async ({ path }) => {
const fileContent = await readFile(path, "utf-8");
const hasDecorators = findDecorators(fileContent);
if (!hasDecorators) return { contents: fileContent };
return { contents: transpileModule(fileContent, config as unknown as TranspileOptions).outputText };
});
},
}; This plugin parses files that contains decorators using typescript
import * as entities from "./entities"
MikroORM.init({
entities: [...Object.values(entities)]
}) |
Current ts-node output with the above reproduction (after fixing some type errors): $ ts-node ./src/index.ts
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
--------------------
at Protocol._enqueue (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at PoolConnection.connect (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/Connection.js:116:18)
at Pool.getConnection (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/Pool.js:48:16)
at /home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:1268:18
at new Promise (<anonymous>)
at MysqlDriver.createPool (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:1265:16)
at MysqlDriver.connect (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/typeorm/src/driver/mysql/MysqlDriver.ts:400:36)
at DataSource.initialize (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/src/data-source/DataSource.ts:252:47)
at Object.<anonymous> (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/src/index.ts:4:15) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
} Output with bun: bun run ./src/index.ts
105 | if (!callSiteStack || typeof callSiteStack !== 'string') {
106 | // No recorded call site
107 | return;
108 | }
109 |
110 | if (err.stack.indexOf(LONG_STACK_DELIMITER) !== -1) {
^
TypeError: undefined is not an object (evaluating 'err.stack.indexOf')
at _addLongStackTrace (/home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/protocol/sequences/Sequence.js:110:7)
at /home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/protocol/sequences/Sequence.js:65:5
at /home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/protocol/Protocol.js:369:5
at /home/zikoat/dev/typerom-repro/bun-typeorm-issue/node_modules/mysql/lib/Connection.js:418:3
at node:net:375:35 However, when fixing the undefined reference, we get the error: bun run ./src/index.ts
ECONNREFUSED: Failed to connect
syscall: "connect" Which doesnt include the yrl, but the error looks a bit nicer. I guess this can be closed, unless you guys want to fix the differing behavior regarding the error. |
This |
What version of Bun is running?
0.7.3
What platform is your computer?
Linux 5.15.0-78-generic x86_64 x86_64
What steps can reproduce the bug?
Clone this repo:
This was generated using typeorm cli and I updated some stuff in tsconfig and dependencies.
Install dependencies
(Optional) Setup a local mysql server at port 3306. This step is optional because we can reproduce the error before even typeorm attempts to connect to a db.
Run file
What is the expected behavior?
The file should run successfully and print some logs of adding a user (If db successfully setup) or show that the connection was not found.
What do you see instead?
Additional information
This is what my
tsconfig.json
looks like:Looks like Bun is ignoring "emitDecoratorMetadata" present in my tsconfig. Or does it not support it?
The text was updated successfully, but these errors were encountered: