If you want to run "ts-node" in production with ESM, then use: "tsc --noEmit && node --no-warnings=ExperimentalWarning --loader ts-node/esm/transpile-only src/main.ts" (see github.com/TypeStrong/ts-node/issues/104#issuecomment-1941702624)
Thank you, Daniel! It's important for me to not only show the "how" but also explain the "why". I try to follow this principle in all my TypeScript tutorials. 😀
😮 Mouth fell open watching this. There's no way that today's copy/paste developers are going to create quality software with scenarios like this. I've been doing this for decades, have been following advice for all of these various tools, to solve these problems, and had no clue about the details that you provided here. OMG - Thank you! I need to change my approach to this tooling ... maybe go back to BASIC. 😂
Thanks for your comprehensive video! I was struggling with those errors for 5 hours before finding a solution. I tried tsx and noticed that while it’s fast, it lacks type checking. Finally, I ended up using the command: nodemon --exec node --loader ts-node/esm src/index.ts This setup does perform type checking. For example, if you write let x: string = 20, nodemon crashes the app with an error. However, I noticed that, like node with ts-node/esm, it doesn’t provide a stack trace for errors. Do you have any suggestion?
Hi @mahdiahmadi504, to get stack traces, you can use tsimp (14:58) or run tsc --noEmit before executing ts-node-esm, as shown here: typescript.tv/hands-on/write-a-simple-typescript-script-with-esm/#fixing-err_unknown_file_extension
If you want to run "ts-node" in production with ESM, then use: "tsc --noEmit && node --no-warnings=ExperimentalWarning --loader ts-node/esm/transpile-only src/main.ts" (see github.com/TypeStrong/ts-node/issues/104#issuecomment-1941702624)
Thank you Benny! Amazing video, not only sharing the solution but explaining why it's the best solution available at the moment! Tks a lot
Thank you, Daniel! It's important for me to not only show the "how" but also explain the "why". I try to follow this principle in all my TypeScript tutorials. 😀
This is easily the most underrated TS channel on RUclips. Thank you for your videos Benny.
Thank you! I also think the same. 😅 Btw. I made an app for programmers: apps.apple.com/app/id659282498
😮 Mouth fell open watching this. There's no way that today's copy/paste developers are going to create quality software with scenarios like this.
I've been doing this for decades, have been following advice for all of these various tools, to solve these problems, and had no clue about the details that you provided here. OMG - Thank you!
I need to change my approach to this tooling ... maybe go back to BASIC. 😂
Great video. That was the last thing I couldn't figure out in my ts node setup
Excellent videos .. one of the best videos in TS
Thank you! It's also reported that using "vite-node src/main.ts" is a viable option.
Thank you so much for your explanation, it helped me a lot
Thanks for your comprehensive video! I was struggling with those errors for 5 hours before finding a solution. I tried tsx and noticed that while it’s fast, it lacks type checking. Finally, I ended up using the command:
nodemon --exec node --loader ts-node/esm src/index.ts
This setup does perform type checking. For example, if you write let x: string = 20, nodemon crashes the app with an error. However, I noticed that, like node with ts-node/esm, it doesn’t provide a stack trace for errors. Do you have any suggestion?
Hi @mahdiahmadi504, to get stack traces, you can use tsimp (14:58) or run tsc --noEmit before executing ts-node-esm, as shown here: typescript.tv/hands-on/write-a-simple-typescript-script-with-esm/#fixing-err_unknown_file_extension
can we run this main.ts directly in the aws lambda or do we need to convert to js ?? i am not sure how can we use this for aws lambda ??
To use your TypeScript code with AWS Lambda, you need to convert it to JavaScript: docs.aws.amazon.com/lambda/latest/dg/lambda-typescript.html
Its so stupid that ts-node --esm is not working with node v20+
Thanks but what if i have to use nodemon
When using nodemon, you can create a "nodemon.json" file in your repository and use the commands in the "exec" section.
can be
nodemon --exec node --loader ts-node/esm index.ts
how to do it with nodemon "node --loader ts-node/esm && nodemon ./index.ts"
Will you get type checking when doing this?
I think u mean smt like this
nodemon --exec node --loader ts-node/esm index.ts