Trying to setup TS for es6 module. I'm using node version v20.12.1. I've tried switching to different node versions.
I'm just using 1file 1 line, console.log() for initial setup.
Any help is appreciated, many thanks!
39 messages · Page 1 of 1 (latest)
Trying to setup TS for es6 module. I'm using node version v20.12.1. I've tried switching to different node versions.
I'm just using 1file 1 line, console.log() for initial setup.
Any help is appreciated, many thanks!
Do you not know how to use import?
!screenshot
Rather than screenshots, please provide either code formatted as:
```ts
// code here
```
Or even better, as an example on the TypeScript playground that is as simple as possible and reproduces the issue. This makes it easier to help you and increases the chances of getting an answer.
but we don't really need all of that, showing the part that's actually giving errors would help
Yep, but import what?
I've written expressJS code in Es6 module.
Just that I'm trying to add TS to that
I'm just using console.log() for now....1 file 1 line.
I messed up my main code so jusr seeing if this works
Still the same error.
I read couple of article that thr node version can be issue, but I've switched to latest one, the prev i was using was v15.
Still the same err for both
what does D:\test\app.ts look like? (and as previously suggested: code as text is better than a screenshot)
Hey,
Thanks for reaching out.
As said in above comments, I'm just using 1file 1 line console.log for my index.ts as I've messed up my main code
Nws, i updated the post, cheers
maybe this is a known issue with ts-node-dev: https://github.com/wclr/ts-node-dev/issues/314?
i don't think i've used that package. you could try compiling with tsc and then running via node to see if you get the same issue or not. i know tsx is also popular these days
Ah, many thanks for the article, issue looks the exact same....
while ts-node is convenient, I'd recommend not to use it for beginners, since it requires quite a bit of prior knowledge about module systems in JS
you need to pass --esm when calling ts-node
you can see in the logs the ts-node loader is cjs, which won't work with es modules
also express is a cjs package, so you will need esModuleInterop, but I see you already have it enabled, so that's good
@thorny fern
Thanks for the suggestion....I'm self learning so need to start from somewhere right🙃...
I'll checkout the given link, thanks!
also you should have "type": "module" in your package.json
for nodejs to start in esm mode
but tbh, I wouldn't go down that road
👉 it's way easier to just use cjs when getting started @thorny fern
especially if you don't have any specific reason to use esm
The cjs one is working fine with ts....thing is I've worked on express on es6, so need to setup ts on es module to setup ts on the main express code
so need to setup ts on es module to setup ts on the main express code
wdym?
I mean I've given type: module as coz I've written express code on es6.
So I'm not checking out TS in cjs