NestJS:添加 cookie 解析器会导致错误

Nic*_*ire 0 cookies nestjs

当我运行此代码时:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import cookieParser from 'cookie-parser';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use(cookieParser());
  await app.listen(3000);
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)

我得到:

(node:28) UnhandledPromiseRejectionWarning: TypeError: cookie_parser_1.default is not a function
    at bootstrap (/usr/src/app/dist/main.js:8:36)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Run Code Online (Sandbox Code Playgroud)

如果我注释掉“app.use(cookieParser());” 问题消失了,但我需要 cookie 解析器。

Nic*_*ire 7

当我即将点击提交时,我确实发现了这一点。

修改上面的有

import * as cookieParser from 'cookie-parser';
Run Code Online (Sandbox Code Playgroud)

它按预期工作。