dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.8k stars 100 forks source link

[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "[...]/tsconfig.json" needs an import assertion of type "json" #207

Open kran6a opened 2 years ago

kran6a commented 2 years ago

I am getting this error on node 17.9.0 when using tsconfig-paths from mocha through ts-node.

mocha command: mocha -n experimental-specifier-resolution=node -n loader=ts-node/esm --serial -p tsconfig.json --spec ./test/**/*.spec.ts

tsconfig.json:

{
    "extends": "./.svelte-kit/tsconfig.json",
    "compilerOptions": {
        "baseUrl": ".",
        "rootDir": ".",
        "module": "ESNext",
        "target": "ESNext",
        "lib": ["ESNext"],
        "typeRoots" : ["./node_modules/@types", "./src"],
        "sourceMap": true,
        "resolveJsonModule": true,
        "alwaysStrict": true
    },
    "typeAcquisition": {
        "enable": true
    },
    "ts-node": {
        "require": ["tsconfig-paths/register"],
        "compilerOptions": {
            "resolveJsonModule": true
        }
    },
    "paths": {
        "$src/*": ["src/*"],
        "$lib/*": ["src/lib/*"],
        "$api/*": ["src/routes/api/*"],
        "$app/*": [".svelte-kit/runtime/app/*"]
    }
}

Unfortunately no stack trace is shown so I don't know where the failing import is taking place but is should be as easy to fix as adding assert { type: 'json' } after the import like import tsconfig from './tsconfig.json' assert { type: 'json' };.