swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.78k stars 75 forks source link

Unable to use JSON modules with `@swc-node/register` #774

Closed maxburs closed 4 months ago

maxburs commented 4 months ago

I've tried: node --import @swc-node/register/esm-register script.ts SWCRC=true node --import @swc-node/register/esm-register script.ts SWC_NODE_PROJECT=null node --import @swc-node/register/esm-register script.ts

with no luck

If I set jsc.experimental.keepImportAssertions then I can get the cli to produce output that works.

image

Node v20.13.1 macOS 14.4.1 (23E224) Yarn 4.2.2 (node_modules linker)

tsconfig.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "extends": "@tsconfig/node20/tsconfig.json",
  "compilerOptions": {
    "lib": ["es2023"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "target": "esnext",
    "resolveJsonModule": true
  }
}

.swcrc

{
  "$schema": "https://swc.rs/schema.json",
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "importMeta": true
    },
    "target": "es2022",
    "experimental": {
      "keepImportAssertions": true
    }
  },
  "isModule": true
}

Reproduction: https://github.com/maxburs/swc-node