Typescript/Node Unexpected token *

I had the same problem, after I realised that the tsconfig wasn't applied.

If

"module": "commonjs" 

was in effect, you wouldn't have this error.


I faced the same problem before. I solve it by changing the import 'call':

From:

import * as express from 'express';

To:

const express = require('express');

As others have stated, the problem is that your tsconfig.json is not applied to server.ts. You have left out important details of your setup which is why others cannot duplicate this problem.

I have a good guess at what the issue is and having struggled with this identical problem myself, I will explain my guess here in the hope of helping some other poor soul being tormented by this issue.

The basic problem is that your server code is in a different tree than your react code. This is why the tsconfig.json is not being applied to it since (I believe) it is outside the "./src/" path specified. (Perhaps "./website/src/").

You haven't shown us the package.json file but very likely the server entry is something like "server": "ts-node ./website/src/server.ts"

To verify that the tsconfig.json application is the issue try this from the command line...

$ ts-node -O '{\"module\":\"commonjs\"}' ./website/src/server.ts

Chances are, things will start working. Now the solution is probably as simple as adding another path your tsconfig.json includes.