Using with Typescript #33
Replies: 4 comments
-
As a follow-up, there seems to be some issue with how Jest compiles the code. I have the following configuration in
|
Beta Was this translation helpful? Give feedback.
-
This is really a TypeScript configuration issue, which is not something I have a lot of knowledge about, but I'll do my best to help. Here's the setup that I use for running one-off TS code with
{
"compilerOptions": {
"module": "es2020",
"target": "es2015",
"moduleResolution": "Node16",
"esModuleInterop": true,
"strict": true
}
} I don't remember what all of those things do, but iirc,
{
...
"type": "module",
...
} This sets the node project to use ESM instead of the default CommonJS. If you want/need your node project to use CommonJS instead, I think you'd need to remove |
Beta Was this translation helpful? Give feedback.
-
For mocha I had to configure a "loader" specifically for supporting ESM libraries. There might be some similar configuration for Jest. |
Beta Was this translation helpful? Give feedback.
-
If your code runs through a bundler (aka any transpilation tool which is not typesript), then you should try running with |
Beta Was this translation helpful? Give feedback.
-
My apologies if this question is off topic.
I am following the example on the main readme.md. When I import as in the example code in a unit test
ts
file:import { addSchema, validate, } from '@hyperjump/json-schema/draft-2020-12';
I get the following error:
SyntaxError: Cannot use import statement outside a module
I recognize that this is related to different module formats, but I'm not exactly sure how to resolve it. I have tried making modifications to my
package.json
file and to mytsconfig.json
file, but I still can't get past the error.Beta Was this translation helpful? Give feedback.
All reactions