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

SyntaxError: Unexpected token '?' #722

Open
razr001 opened this issue Aug 10, 2023 · 5 comments
Open

SyntaxError: Unexpected token '?' #722

razr001 opened this issue Aug 10, 2023 · 5 comments

Comments

@razr001
Copy link

razr001 commented Aug 10, 2023

function fun(a?:string){
  console.log(a);
}
fun()

function fun(a?:string){
^

SyntaxError: Unexpected token '?'
at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:119:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:468:14)
at async link (node:internal/modules/esm/module_job:68:21)

Node.js v18.16.1

@ekscentrysytet
Copy link

Also happens for me when running:

SWCRC=true node --loader @swc-node/register/esm scripts/run-local.ts
"@swc-node/register": "1.6.8"

@mishelen
Copy link

mishelen commented Apr 6, 2024

the same here

tsoa builds routes & swaggers specs under backend/build folder,
then swc should run app from backend/src

> npm run swagger && SWCRC=true dotenv -e .env.local -- node --import @swc-node/register/esm-register src/server.ts


> tsoa spec-and-routes

file:///.........backend/build/routes.ts:7
import type { Request as ExRequest, Response as ExResponse, RequestHandler, Router } from 'express';
            ^

SyntaxError: Unexpected token '{'
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:155:18)
    at callTranslator (node:internal/modules/esm/loader:285:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:30)

Node.js v20.10.0

@swc-node/register: 1.9.0

@kdy1
Copy link
Member

kdy1 commented Apr 6, 2024

Do you have a minimal reproduction?

@mishelen
Copy link

mishelen commented Apr 6, 2024

hey @kdy1

I've created repo https://github.com/mishelen/tsoa-swc/tree/main
Please take a look

@mishelen
Copy link

mishelen commented Apr 6, 2024

if I manually remove type from import then it fail on next statement.

file:///.../build/routes.ts:13
const models: TsoaRoute.Models = {
      ^^^^^^

SyntaxError: Missing initializer in const declaration

Uhhh, but it IS initialized. Even more I don't see any errors from TS in that file in the IDE.
UPDATE: whole typescript file is treated as just javascript, only after I'd removed all annotations, it started work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants