swc-project / swc-project/swc-node
Decorators support with @node-swc/register sparks problems. Nothing works :'(
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 95
- Avg merge
- 14d 11h
- Merged PRs (30d)
- 1
Description
When trying to transcompile my typescript files I get this error :'(
Node: 19.8.1
Npm: 9.6.2
PS F:\Discord\Bot> npm run dev
> computronium@1.0.0 dev
> cross-env NODE_ENV=development nodemon --exec node -r @swc-node/register src/main.ts
[nodemon] 2.0.22
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: ts,json
[nodemon] starting `node -r @swc-node/register src/main.ts`
F:\Discord\Bot\node_modules\@swc\core\index.js:241
return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
^
Error:
× Expression expected
╭─[F:\Discord\Bot\src\api\server.ts:7:1]
7 │ import { Log } from "@api/middlewares"
8 │ import { PluginsManager } from "@services"
9 │
10 │ @singleton()
· ─
11 │ export class Server {
12 │
13 │ @Inject() app: PlatformApplication
╰────
Caused by:
Syntax Error
at Compiler.transformSync (F:\Discord\Bot\node_modules\@swc\core\index.js:241:29)
at transformSync (F:\Discord\Bot\node_modules\@swc\core\index.js:348:21)
at transformSync (F:\Discord\Bot\node_modules\@swc-node\core\index.ts:69:26)
at compile (F:\Discord\Bot\node_modules\@swc-node\register\register.ts:91:40)
at exts (F:\Discord\Bot\node_modules\@swc-node\register\register.ts:106:38)
at Module._compile (F:\Discord\Bot\node_modules\pirates\lib\index.js:130:29)
at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
at Object.newLoader [as .ts] (F:\Discord\Bot\node_modules\pirates\lib\index.js:141:7)
at Module.load (node:internal/modules/cjs/loader:1133:32)
at Function.Module._load (node:internal/modules/cjs/loader:972:12) {
code: 'GenericFailure'
}
Node.js v19.8.1
[nodemon] app crashed - waiting for file changes before starting...
Here is my .swcrc file:
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"target": "es2021",
"baseUrl": "./",
"paths": {
"@decorators": [ "src/utils/decorators" ],
"@decorators/*": [ "src/plugins/*/utils/decorators" ],
"@errors": [ "src/utils/errors" ],
"@errors/*": [ "src/plugins/*/utils/errors" ],
"@entities": [ "src/entities" ],
"@entities/*": [ "src/plugins/*/entities" ],
"@guards": [ "src/guards" ],
"@guards/*": [ "src/plugins/*/guards" ],
"@services": [ "src/services" ],
"@services/*": [ "src/plugins/*/services" ],
"@i18n": [ "src/i18n" ],
"@i18n/*": [ "src/plugins/*/i18n" ],
"@config": [ "src/config" ],
"@config/*": [ "src/plugins/*/config" ],
"@utils/classes": [ "src/utils/classes" ],
"@utils/classes/*": [ "src/plugins/*/utils/classes" ],
"@utils/functions": [ "src/utils/functions" ],
"@utils/functions/*": [ "src/plugins/*/utils/functions" ],
"@api/controllers": [ "src/api/controllers" ],
"@api/controllers/*": [ "src/plugins/*/api/controllers" ],
"@api/middlewares": [ "src/api/middlewares" ],
"@api/middlewares/*": [ "src/plugins/*/api/middlewares" ],
"@api/server": [ "src/api/server.ts" ]
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
}
},
"exclude": [ "node_modules", ".git" ],
"module": {
"type": "commonjs",
"noInterop": true
}
}
Here is my tsconfig.json file:
"compilerOptions": {
"target": "es2021",
"module": "commonjs",
"outDir": "./build",
"rootDir": ".",
"strict": true,
"strictPropertyInitialization": false,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"skipLibCheck": false,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@decorators": [ "src/utils/decorators" ],
"@decorators/*": [ "src/plugins/*/utils/decorators" ],
"@errors": [ "src/utils/errors" ],
"@errors/*": [ "src/plugins/*/utils/errors" ],
"@entities": [ "src/entities" ],
"@entities/*": [ "src/plugins/*/entities" ],
"@guards": [ "src/guards" ],
"@guards/*": [ "src/plugins/*/guards" ],
"@services": [ "src/services" ],
"@services/*": [ "src/plugins/*/services" ],
"@i18n": [ "src/i18n" ],
"@i18n/*": [ "src/plugins/*/i18n" ],
"@config": [ "src/config" ],
"@config/*": [ "src/plugins/*/config" ],
"@utils/classes": [ "src/utils/classes" ],
"@utils/classes/*": [ "src/plugins/*/utils/classes" ],
"@utils/functions": [ "src/utils/functions" ],
"@utils/functions/*": [ "src/plugins/*/utils/functions" ],
"@api/controllers": [ "src/api/controllers" ],
"@api/controllers/*": [ "src/plugins/*/api/controllers" ],
"@api/middlewares": [ "src/api/middlewares" ],
"@api/middlewares/*": [ "src/plugins/*/api/middlewares" ],
"@api/server": [ "src/api/server.ts" ]
}
},
"include": ["src", "**/*.ts"],
"exclude": ["build", "node_modules", "tests"],
"paths": ["node_modules/*", "src/utils/types/*", "src/plugins/*/utils/types/*"],
"ts-node": {
"require": [ "tsconfig-paths/register" ],
"swc": true
}
}
Any idea on how to fix the issue? Thank you in advance i have been stuck with this issue since 3 days now :(
Side note: The error appeared once I upgraded my node version to 19.x
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce with npm run dev, which loads src/main.ts through @swc-node/register and fails while compiling src/api/server.ts. Compare the decorator settings in .swcrc with tsconfig.json, using the shown @singleton() and @Inject() declarations as the repro. Done means the same command compiles the decorated TypeScript without the syntax error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100