helmetjs / helmet

Help secure Express apps with various HTTP headers

Home Page:https://helmetjs.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Helmet 6.1.2: 'typeerror (0 helmet_1.default) is not a function' when using helmet

ctanejaex2 opened this issue · comments

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

Using helmet gives error typeerror (0 helmet_1.default) is not a function on app.use(helmet).
This was working fine util day before yesterday. Any solutions? :/

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

What does your tsconfig.json file look like?

I will try installing helmet6.0.1
Furthermore, here is my tsconfig.json

  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}
```

I'm unable to reproduce your issue. Did you specify "type": "module" in your package.json? Could you create a small sample project?

I encountered the same error after upgrading from 6.0.1 to 6.1.2 - i use NestJS with Typescript. Reverting to 6.0.1 will make the error disappear again.

....../src/main.ts:56
  app.use(helmet());
                ^
TypeError: (0 , helmet_1.default) is not a function

Greets
-act

@actraiser I can't reproduce this issue. Could you create a sample project or show me your tsconfig.json?

Here is a repo with a freshly initialized nestjs application that uses helmet in src/main.ts

https://github.com/actraiser/nestjs-helmet-error

on yarn run start it will throw an error when using 6.1.2 - otherwise (when installing helmet 6.0.1) no error is thrown.

❯ yarn run start
yarn run v1.22.19
$ nest start
[Nest] 35400  - 10.04.2023, 16:19:21     LOG [NestFactory] Starting Nest application...
[Nest] 35400  - 10.04.2023, 16:19:21     LOG [InstanceLoader] AppModule dependencies initialized +11ms

/development/playground/nestjs-helmet-error/src/main.ts:7
  app.use(helmet());
                ^
TypeError: (0 , helmet_1.default) is not a function
    at bootstrap (/development/playground/nestjs-helmet-error/src/main.ts:7:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Greets
-act

@actraiser Thank you for the sample app. I can reproduce it and will prepare a fix ASAP.

For anyone experiencing this problem, helmet@6.0.1 should work fine until I fix it.

@actraiser Strangely, yarn build works fine but yarn start doesn't. I don't know why but am investigating a fix.

This should be fixed in helmet@6.1.3. Let me know if you're still running into problems!