18

My error is:

Error: src/app.ts(11,13): error TS2349: This expression is not callable.
  Type 'typeof import("express")' has no call signatures.

My tsconfig.json is:

{
    "compilerOptions": {
        "outDir": "./built",
        "allowJs": true,
        "target": "es6",
        "esModuleInterop": true
    },
    "include": [
        "./src/**/*"
    ]
}

My src/app.ts has:

// const Logger = require('./lib/logger')
import express from 'express';
import bodyParser from 'body-parser';
// const finale = require('finale-rest')
// const morgan = require('morgan')
const DB = require('./models')()


// const resources = require('./resources')

const app = express()

The line in question is const app = express()

What am I doing wrong?

Shamoon
  • 41,293
  • 91
  • 306
  • 570

3 Answers3

30

Make sure you don't have "esModuleInterop": true set in tsconfig.json. Disabling this setting resolved the issue for me.

Nathan Hopper
  • 335
  • 1
  • 3
  • 6
  • For me winwiz1's solution was already in place but I was still getting the error. Doing as Nathan Hopper suggested on top of that resolved the issue for me. – Brandon Avant Jan 19 '20 at 06:49
  • 4
    Read this to learn why you should **not** remove "esModuleInterop" from your tsconfig.json: https://stackoverflow.com/a/56348146/2678608 (if you're on TS version 2.7+) – developer Feb 05 '20 at 22:36
  • 1
    Yeah but what is if you have references which needs that interop settings like me? – Michael Baarz Jan 27 '21 at 10:00
  • Solved with this solution, having trouble implementing LRUCache lib, this solved the issue. – Wallysson Nunes Oct 20 '22 at 20:10
23

To make this work with "esModuleInterop": true set to true in your tsconfig.json you can also do this.

import * as express from 'express';
...
const app = express.default();

source

s-dehaan
  • 271
  • 2
  • 3
  • This answer needs to be upvoted more. I can't believe this solution isn't more widely known. – qz- Jun 28 '23 at 02:54
12

Add @types/express and then:

import * as express from "express";
...
const app = express();
winwiz1
  • 2,906
  • 11
  • 24