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

Helmet 6.1.2: Type 'typeof import("/srv/www/cz.vegilove.api/node_modules/helmet/index")' has no call signatures. #414

Closed
rostalevicek opened this issue Apr 10, 2023 · 11 comments

Comments

@rostalevicek
Copy link

import helmet from 'helmet';
app.use(helmet())

Leads to error:

error TS2349: This expression is not callable.
Type 'typeof import("/srv/www/cz.vegilove.api/node_modules/helmet/index")' has no call signatures.
app.use( helmet() )

The probelm is default export. It exports the object of named functions, therefore it is possible to use helmet.xxxx() but it does not include "function helmet()".

One possible solution is to include "helmet" in named exports... i guess

@EvanHahn
Copy link
Member

In the short term, you can fix this by installing helmet@6.0.1.

What does your tsconfig.json file look like?

@rafaberaldo
Copy link

Having the same error with v6.1.2

My tsconfig:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "Node16",
    "moduleResolution":"Node16",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "skipLibCheck": true,
    "rootDir": "./src",
    "baseUrl": ".",
    "paths": {
      "#api/*": ["./src/*"]
    }
  },
  "include": ["src/**/*.ts", "src/**/*.d.ts"]
}

@EvanHahn
Copy link
Member

I made the following app and could not reproduce your issue:

package.json
{
  "scripts": {
    "build": "tsc"
  },
  "dependencies": {
    "helmet": "^6.1.2",
    "typescript": "^5.0.4"
  }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "Node16",
    "moduleResolution":"Node16",
    "outDir": "./dist",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "skipLibCheck": true,
    "baseUrl": "."
  },
  "include": ["app.ts"]
}
app.ts
import helmet from "helmet";

helmet();

Everything seemed to work fine when I run npm run build.

What version of TypeScript are you using? What about the version of Node.js? Is anything special happening in your package.json?

@EvanHahn
Copy link
Member

I just published helmet@6.1.3 to fix a similar issue. Is it possible that upgrading fixes your problem too? (I doubt it, but I'm hopeful!)

@rafaberaldo
Copy link

What version of TypeScript are you using? What about the version of Node.js? Is anything special happening in your package.json?

Typescript v5.0.4
package.json with "type": "module", maybe that's the issue?

@rafaberaldo
Copy link

I just published helmet@6.1.3 to fix a similar issue. Is it possible that upgrading fixes your problem too? (I doubt it, but I'm hopeful!)

Just tried with v6.1.3 still same issue unfortunately. I'll setup a repro.

@rafaberaldo
Copy link

rafaberaldo commented Apr 10, 2023

@EvanHahn OK from what I've seem the problem is type: module

repro: https://github.com/rafaelpimpa/helmet-issue-414

I think it's easily fixable with "exports" key in package.json: https://nodejs.org/api/packages.html#main-entry-point-export

@EvanHahn
Copy link
Member

EvanHahn commented Apr 10, 2023

@rafaelpimpa Thanks, this is very helpful. I'll deploy a fix ASAP. (If you know exactly how to fix this, let me know. Otherwise I'll start digging.) Update: I believe I have a fix.

@EvanHahn
Copy link
Member

This should be fixed in helmet@6.1.4. Let me know if you run into any other problems. Sorry for the trouble!

@rostalevicek
Copy link
Author

I also have still the problem. When launched using ts-node with some specail params, i can use it in dev, but to build production code with tsc (typescript 5.0.4), will fail with error:

node_modules/helmet/index.d.ts:120:1 - error TS2309: An export assignment cannot be used in a module with other exported elements.

120 export = helmet
~~~~~~~~~~~~~~~

My tsconfig looks like:
{ "compileOnSave": false, "compilerOptions": { "outDir": "./dist", "target": "ESNext", "module": "ESNext", "moduleResolution": "NodeNext", "jsx":"react-jsx", "allowSyntheticDefaultImports": true, "preserveSymlinks": true, "resolveJsonModule": true, "esModuleInterop": true, "declaration": false, "noImplicitThis": true, "strictNullChecks": true, "lib": [ "ESNext", "DOM" ], "typeRoots": [ "src/@types", "node_modules/@types" ], "sourceMap": true, "plugins": [ { "transform": "@formatjs/ts-transformer", "import": "transform", "type": "config", "overrideIdFn": "[sha512:contenthash:base64:6]", "ast": true } ] }, "include": [ "src/**/*", "utils/**/*" ], "exclude": [ "node_modules" ] }

And i am using esm ("type":"module" in package.json).

@EvanHahn
Copy link
Member

@rostalevicek Sorry about this. Let's move discussion to #419.

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

No branches or pull requests

3 participants