Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression is not callable in 4.0.0 #236

Closed
marluanespiritusanto opened this issue Aug 2, 2020 · 8 comments
Closed

Expression is not callable in 4.0.0 #236

marluanespiritusanto opened this issue Aug 2, 2020 · 8 comments

Comments

@marluanespiritusanto
Copy link

After updating to 4.0.0 version the helmet middleware configuration throws an error:

This expression is not callable.
 Type 'typeof import("/node_modules/helmet/dist/index")' has no call signatures.ts(2349)

This is the code Im trying to run:

import * as helmet from 'helmet';
import * as express from "express";

const app = express();

// express middleware configuration
app.use(helmet())
@marluanespiritusanto marluanespiritusanto changed the title Expression is not callable on 4.0.0 Expression is not callable in 4.0.0 Aug 2, 2020
@EvanHahn
Copy link
Member

EvanHahn commented Aug 2, 2020

What does your tsconfig.json look like, if you can share it?

@marluanespiritusanto
Copy link
Author

@EvanHahn Here it is

{
  "compilerOptions": {
    "paths": {
      "@modules/*": ["./src/modules/*"],
      "@database/*": ["./src/database/*"],
      "@common/*": ["./src/common/*"],
      "@utils/*": ["./src/utils/*"]
    },
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}

@EvanHahn
Copy link
Member

EvanHahn commented Aug 2, 2020

Would you be willing to enable esModuleInterop, if that fixes your problem?

@hongbo-miao
Copy link

hongbo-miao commented Aug 3, 2020

Hi @marluanespiritusanto My upgrading experience was smooth. I just upgraded to helmet 4.0.0, the code is at https://github.com/Hongbo-Miao/hongbomiao.com/blob/master/server/src/security/middlewares/helmet.middleware.ts
tsconfig.json is at https://github.com/Hongbo-Miao/hongbomiao.com/blob/master/server/tsconfig.json

I am using "module": "esnext", but I also succeed on "module": "commonjs".
See if my tsconfig.json helps locate the issue.

@joshuajung
Copy link

I'm facing the same issue, and unfortunately esModuleInterop does not seem to fix it - still getting the no call signatures error. My full tsconfig.json, with TS 3.9.7:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "incremental": true,
    "strict": true,
    "esModuleInterop": true,
  },
  "exclude": ["node_modules", "dist"]
}

@anthony-telljohann
Copy link

I was able to resolve this by ignoring typescript errors before using helmet

import * as helmet from 'helmet'
...
// @ts-ignore
app.use(helmet(helmetConfig))

I believe this is because the default helmet export has an incorrectly defined type.

@EvanHahn
Copy link
Member

EvanHahn commented Aug 3, 2020

I'd like to fix the Helmet types.

Helmet is a CommonJS module (in other words, it uses module.exports and not export ...). Therefore, without esModuleInterop, I would expect users to do something like this:

import helmet = require("helmet");

Though I'm not an expert at how TypeScript modules work.

@EvanHahn
Copy link
Member

EvanHahn commented Aug 3, 2020

This issue looks the same as #235, so I'm going to close this issue and move discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants