swc-node icon indicating copy to clipboard operation
swc-node copied to clipboard

Syntax error after updating to 1.6.8

Open MrFoxPro opened this issue 2 years ago • 8 comments

After upgrading from 1.6.7 to 1.6.8, I get following error:

[api] 
[api] node:internal/process/esm_loader:48
[api]       internalBinding('errors').triggerUncaughtException(
[api]                                 ^
[api] [Error: 
[api]   x Expected ',', got '{'
[api]    ,-[file:///home/foxpro/craft/sferadel/dev/api/main.mts:2:1]
[api]  2 | import * as path from "node:path"
[api]  3 | import { availableParallelism } from "node:os"
[api]  4 | import * as fs from "node:fs/promises"
[api]  5 | import type { Worker } from "node:cluster"
[api]    :             ^
[api]  6 | import cluster from "node:cluster"
[api]  7 | import { match } from "ts-pattern"
[api]  8 | import { createYoga } from "graphql-yoga"
[api]    `----
[api] 
[api] 
[api] Caused by:
[api]     Syntax Error] {
[api]   code: 'GenericFailure'
[api] }
[api] 
[api] Node.js v20.6.1
[api] [[Command exited with 1]]

My .swcrc:

{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "baseUrl": ".",
    "parser": {
      "syntax": "typescript"
    },
    "target": "esnext",
    "loose": true,
    "paths": {
      "#/*": ["./*"],
      "#eql": ["./eql/index.mts"],
      "#eql/types": ["./eql/types.d.ts"]
    }
  },
  "module": {
    "type": "es6"
  }
}
My tsconfig.json
{
  "compilerOptions": {
    "strict": false,
    "strictNullChecks": true,
    "strictFunctionTypes": true,

    "baseUrl": ".",
    // "sourceMap": true, // mandatory for SWC
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    // "resolvePackageJsonImports": true,
    // https://github.com/swc-project/swc-node/pull/723
    "paths": {
      "#/*": ["./*"],
      "#eql": ["./eql/index.mts"],
      "#eql/types": ["./eql/types.d.ts"]
    },

    "noEmit": true,
    "isolatedModules": true,

    "skipDefaultLibCheck": true,
    "skipLibCheck": true
  },
  "exclude": ["**/node_modules", "**/.*/"]
}

I tried with "@swc/core": "^1.3.86" and "@swc/core": "^1.3.90", no difference.

MrFoxPro avatar Sep 29 '23 13:09 MrFoxPro

Also got error on importing: Error [ERR_MODULE_NOT_FOUND]: Cannot find module for path alias in tsconfig's paths, but works perfectly fine with v1.6.7.

dmythro avatar Sep 29 '23 14:09 dmythro

I authored the PR #727 and I suspect that the PR broke something. I'm going to figure it out.

cm-ayf avatar Oct 01 '23 03:10 cm-ayf

I got the following message from v1.6.8, but not from v1.6.7. This is using esm and the npm package mysql2,

const [tableNames] = await mysqlPool().query<RowDataPacket[]>(·
                                                                  ^···
    SyntaxError: Unexpected token ']'·

EffectivelyEfficient avatar Oct 15 '23 21:10 EffectivelyEfficient

same issue here!

HashemKhalifa avatar Oct 25 '23 20:10 HashemKhalifa

@cm-ayf any luck with this?

FlorinAsavoaie avatar Jan 24 '24 07:01 FlorinAsavoaie

#754 should fix this. please test and feedback

yeliex avatar Mar 04 '24 02:03 yeliex

Looks good. Can be closed.

FlorinAsavoaie avatar Mar 20 '24 10:03 FlorinAsavoaie

Last release fixed the issue for me

AmauryD avatar Mar 20 '24 10:03 AmauryD