3

Okay,so I have a problem with node. SWC builds everything correctly and I can run the app - great. The problem starts when I try to use "top-level await" feature. I just can't get it to work properly! Changed "module" in package.json, added the top-level await flag in the .swcrc file and... nothing. Does anyone have a repo with SWC and tsconfig properly configured for the modern typescript node?

My SWC config:

{
  "env": {
    "targets": {
      "node": 17
    }
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "topLevelAwait": true
    }
  },
  "module": {
    "type": "commonjs"
  },
  "sourceMaps": "inline"
}

tsconfig:

{
    "extends": "@tsconfig/node18/tsconfig.json",
    "compilerOptions": {
        "target": "es2017",
        "module": "esnext",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "lib": [
            "ESNext"
        ],
        "outDir": "dist",
    },
    "include": [
        "src"
    ],
    "exclude": [
        "node_modules",
        "**/*.test.ts"
    ],
}

My package.json run scripts:

"scripts": {
    "build": "rimraf dist && swc ./src -d dist",
    "build-dev": "npm run build && node --inspect dist/index.js",
    "dev": "nodemon --ext ts --exec \"npm run build-dev\"",
MrVoland
  • 233
  • 1
  • 4
  • 19

0 Answers0