Typescript: Cannot find namespace

In case you are a React dev that ends up here as I did - if there is JSX syntax in the file, try changing the extension of the file from .ts to .tsx.


After a lot of wasted time, it turns out this was due to the module setting in the tsconfig file which should be:

"module": "commonjs"

This means Typescript will output common js modules instead of ES6 modules, meaning the code will run correctly as NodeJS code. I was therefore able to change require to import, since it compiles.


Maybe you have to use import instead of require:

import * as express from 'express';