Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript with Express: Type 'typeof import("express")' has no call signatures

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?

like image 410
Shamoon Avatar asked Sep 21 '19 15:09

Shamoon


3 Answers

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

like image 113
Nathan Hopper Avatar answered Nov 11 '22 19:11

Nathan Hopper


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

like image 15
s-dehaan Avatar answered Nov 11 '22 18:11

s-dehaan


Add @types/express and then:

import * as express from "express";
...
const app = express();
like image 12
winwiz1 Avatar answered Nov 11 '22 20:11

winwiz1