question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

This expression is not callable. error on typescript helmet 5.0.1

See original GitHub issue

The full error is:

src/server/index.ts:6:9 - error TS2349: This expression is not callable.
  Type 'typeof import("C:/try/t21/helet-issue/node_modules/helmet/dist/index")' has no call signatures.

6 app.use(helmet({ contentSecurityPolicy: false }));
          ~~~~~~

Previously in version 4.6.0 it works great, but in the latest helmet 5.0.1 version it does not work. /src/server/index.ts

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


const app = express();
app.use(helmet({ contentSecurityPolicy: false })); // this line shows the error.
app.listen(3002, () => console.log("Server started"));

Here’s my tsconfig:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/server",
        "module": "commonjs",
        "baseUrl": "./",
        "moduleResolution": "node",
        "target": "es2017",
        "lib": [
            "es2020",
            "dom"
        ]
    },
}

You can see this in code sandbox: https://codesandbox.io/s/s4fuq

When I change the import to:

import helmet from 'helmet';

I get a runtime error: TypeError: (0 , helmet_1.default) is not a function

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
MitchellCashcommented, Jan 6, 2022

@EvanHahn I was also seeing this issue in my project and like @GuyMev I would like to avoid modifying my tsconfig.json just for this library.

But the good news, I might have a possible fix to solve everyone’s problems here. I’m not the biggest ESM/CJS/TS expert, but will open a pull request for review and see what you think.

1reaction
paulo-venturacommented, Jan 4, 2022

Setting esModuleInterop to true on tsconfig.json worked for me:

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript error This expression is not callable. #2404 - GitHub
Bug Report I am getting the following error even when using fastify examples from the documentation. src/dist-server.ts:3:16 - error TS2349: ...
Read more >
How to use helmet.js from typescript? - Stack Overflow
I upgraded my helmet version from v 3.23.3 and now I get a compile error "This expression is not callable." for the "helmet()"....
Read more >
helmet - npm
Helmet helps you secure your Express apps by setting various HTTP headers. It's not a silver bullet, but it can help!
Read more >
This expression is not callable. error on typescript helmet 5.0.1
The full error is: src/server/index.ts:6:9 - error TS2349: This expression is not callable.
Read more >
Compare Versions | @brainhubeu/gatsby-docs-kit | npm
We found errors while resolving dependencies that may result in an incomplete or inaccurate dependency graph. Show details. Errors found while resolving some ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found