You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
index.ts:1:41 - error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1 import * as config from './config.json' assert {type:'json'}
~~~~~~~~~~~~~~~~~~~~
Debug log
{"context":{"call":null,"logLevel":10,"namespace":"ts:serviceHost","package":"ts-jest","version":"29.1.1"},"message":"readFile","sequence":412,"time":"2023-09-01T20:04:41.079Z"}
{"context":{"call":null,"logLevel":20,"namespace":"hoist-jest","package":"ts-jest","version":"29.1.1"},"message":"visitSourceFileNode(): hoist jest","sequence":413,"time":"2023-09-01T20:04:41.196Z"}
{"context":{"fileName":"C:\\project\\index.ts","logLevel":20,"namespace":"ts-compiler","package":"ts-jest","version":"29.1.1"},"message":"_doTypeChecking(): computing diagnostics using language service","sequence":414,"time":"2023-09-01T20:04:41.208Z"}
{"context":{"diagnosticCodes":[2821],"diagnosticText":"\u001b[96mindex.ts\u001b[0m:\u001b[93m1\u001b[0m:\u001b[93m41\u001b[0m - \u001b[91merror\u001b[0m\u001b[90m TS2821: \u001b[0mImport assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.\n\n\u001b[7m1\u001b[0m import * as config from './config.json' assert {type:'json'}\n\u001b[7m \u001b[0m \u001b[91m ~~~~~~~~~~~~~~~~~~~~\u001b[0m\n","logLevel":20,"namespace":"TSError","package":"ts-jest","version":"29.1.1"},"message":"created new TSError","sequence":415,"time":"2023-09-01T20:04:41.209Z"}
{"context":{"logLevel":20,"namespace":"ts-jest-transformer","package":"ts-jest","version":"29.1.1"},"message":"created new transformer","sequence":416,"time":"2023-09-01T20:04:41.216Z"}
Additional context
This error happens regardless of whether the Jest config is provided as JSON, JS or TS file.
Also, TS doesn't throw this error when transpiling index.ts file.
In fact, TS throws this error if the value of module is changed from esnext.
So, the value of module is indeed correct, but somehow TS Jest doesn't get it.
On a related note, changing the value of module to some invalid value triggers a different error about the value being invalid:
Would love to get a real solution. For now I suppress the import assertion error using:
// @ts-ignore, because when setting node module resolution to Node16, tsc raises an error for the import assertion.
import configSchema from "./config-schema.json" assert { type: "json" };
Version
29.1.1
Steps to reproduce
With the following TS config:
And, the following Jest config:
A file
index.ts
which imports a JSON file with a type assertion e.g.when imported in a Jest test file e.g.
gives an error.
Expected behavior
Test passes.
Actual behavior
Test fails with a TS error:
Debug log
Additional context
This error happens regardless of whether the Jest config is provided as JSON, JS or TS file.
Also, TS doesn't throw this error when transpiling
index.ts
file.In fact, TS throws this error if the value of
module
is changed fromesnext
.So, the value of
module
is indeed correct, but somehow TS Jest doesn't get it.On a related note, changing the value of
module
to some invalid value triggers a different error about the value being invalid:So, it looks like TS Jest is overriding the
esnext
value.Environment
The text was updated successfully, but these errors were encountered: