I am trying to start a typescript node project and I've installed some dependencies (typescript, eslint, mongoose and graphql). However, when I run
ts-node-dev --respawn --transpile-only src/index.ts
I get the error
Must use import to load ES Module: server/src/index.ts
My index.ts
file is simply:
console.log('Hello world!');
and my tsconfig.json
file is:
{
"compilerOptions": {
"outDir": "./build",
"lib": ["ES2021", "ESNext.AsyncIterable"],
"target": "ES2021",
"module": "ESNext",
"esModuleInterop": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"forceConsistentCasingInFileNames": true,
"strictPropertyInitialization": false,
"strict": true
},
"include": ["./src/**/*"]
}
I have set type
to module
in package.json
.
Try to put this config, may fix your problem:
But check the complete discuss about this problem in ts-node-dev github https://github.com/wclr/ts-node-dev/issues/265
There another options to try.