-1

I have installed typescript in my project and it works fine on the frontend. on the backend I have a node express server. I've started implementing TS there. when I ran the server just now it failed with:

filename: (req: Request, file, cb) => {

SyntaxError: Invalid or unexpected token (pointing at the :)

How can I make TS work on the server?

I've installed esm which allows me to use imports, I've also included: "module": "commonjs" in the package.json

how do I fix this?

Red Baron
  • 7,181
  • 10
  • 39
  • 86

1 Answers1

2

You have to compile the TypeScript into JavaScript (e.g. with tsc) and then run the resulting JavaScript with Node.js (which doesn't have native support for TypeScript).

Alternatively, look at ts-node.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335