Skip to content

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

Description

@maxburs

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions