Usage with TypeORM #1920
Replies: 9 comments 21 replies
-
Does SWC support 'babel-plugin-transform-typescript-metadata'? the config above showing 'decoratorMetadata' suggests it does. Looking to try and change over to swc from babel, as there are some typing issues with babel. 'babel-plugin-transform-typescript-metadata' is the only plugin I cannot find listed on the comparison page by swc. I'm using a typescript project with type-graphql and typegoose which face similar issues as typeorm. |
Beta Was this translation helpful? Give feedback.
-
Any news here? Can anyone share the needed configuration to make TypeORM run with swc? Thanks in advice |
Beta Was this translation helpful? Give feedback.
-
Following up here - is there a work around possibly? |
Beta Was this translation helpful? Give feedback.
-
here's my swcrc: {
"jsc": {
"target": "es2020",
"keepClassNames": true,
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"externalHelpers": false,
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"paths": {
"@/*": [
"./*"
]
},
"baseUrl": "./",
"loose": true
},
"module": {
"type": "commonjs"
}
} My tsconfig: {
"compilerOptions": {
"importHelpers": true,
"removeComments": true,
"noImplicitAny": true,
"typeRoots": [],
"types": [
"node",
"@types/jest",
"@types/enzyme"
],
"baseUrl": ".",
"assumeChangesOnlyAffectDirectDependencies": true,
"paths": {
"@/server": [
"./server"
],
"@/handlers/*": [
"./handlers/*"
],
"@/handlers": [
"./handlers"
],
"@/events/*": [
"./events/*"
],
"@/events": [
"./events"
],
"@/lib/*": [
"./lib/*"
],
"@/lib": [
"./lib"
],
"@/components/*": [
"./components/*"
],
"@/components": [
"./components"
],
"@/client-state/*": [
"./client-state/*"
],
"@/client-state": [
"./client-state"
],
"@/services/*": [
"./services/*"
],
"@/services": [
"./services"
],
"@/repositories/*": [
"./repositories/*"
],
"@/repositories": [
"./repositories"
],
"@/domains": [
"./domains"
],
"@/domains/*": [
"./domains/*"
],
"@/use-cases": [
"./use-cases"
],
"@/use-cases/*": [
"./use-cases/*"
],
"@/utils": [
"./utils"
],
"@/utils/*": [
"./utils/*"
],
"@/__test-utils__/*": [
"./__test-utils__/*"
],
"@/__test-utils__": [
"./__test-utils__"
],
"@/workers/*": [
"./workers/*"
],
"@/workers": [
"./workers"
]
},
"target": "es2017",
"module": "CommonJS",
"lib": [
"dom",
"dom.iterable",
"esnext",
"es5",
"es6"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
},
"include": [
"./lib/types.ts",
"./lib/**/*.ts",
"./repositories/**/*.ts",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"build",
"coverage",
".github",
".next",
".vscode",
"*jest*",
"coverage",
"db-setup",
"generator-seso-domain",
"migrations",
"node_modules",
"scripts*",
"scratch*"
]
} |
Beta Was this translation helpful? Give feedback.
-
Does anyone have a working example using TypeORM and SWC? |
Beta Was this translation helpful? Give feedback.
-
use the decoratorMetadata: true and wrap all your relations in Relation<>
to
Do this for all OneToMany, ManyToOne,OneToOne, ManyToMany... |
Beta Was this translation helpful? Give feedback.
-
Thanks to @hjf comment I got everything running in my NestJS application.
Here is my .swcrc {
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2022",
"loose": false,
"paths": {
"@/*": [
"./*"
]
},
"baseUrl": "./",
"externalHelpers": false,
"keepClassNames": true
},
"module": {
"type": "commonjs",
"strict": true,
"noInterop": false
},
"minify": false,
"sourceMaps": true
} I am also using it with jest where I added to my jest.config.js
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
HI guys, could anyone share what is the recommended config to be used with TypeoORM? I'd like to use
swc
for tests only (@swc/jest
) but I'm getting errors like this for all TypeORM entities:ColumnTypeUndefinedError: Column type for SomeEntityName1#columnName is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
Node: v12.19.0
TypeORM version: 0.2.31
Jest: 26.6.3
swc/jest: 0.1.4
The production code works fine, so do tests with
ts-jest
transformer.reflect-metadata
is imported once in the main file, decorators are enabled in both TS andswc
configs. Here istsconfig.json
:And here is
.swcrc
:I've already tried a number of
swc
configurations but none of them work 😞 I'd really appreciate it if someone could point me in the right direction.Beta Was this translation helpful? Give feedback.
All reactions