【问题标题】:Starting nestjs in production mode在生产模式下启动nestjs
【发布时间】:2020-01-24 19:14:12
【问题描述】:

我正在使用我购买的 akveo 后端捆绑包,虽然在开发模式下一切似乎都运行良好,但从生产开始给我以下错误,但我对 nestjs 本身还是新手。 有人知道这是怎么回事吗?

node_modules/@nestjs/core/adapters/http-adapter.d.ts:5:31 - error TS2420: Class 'AbstractHttpAdapter<TServer, TRequest, TResponse>' incorrectly implements interface 'HttpServer<TRequest, TResponse>'.
    Property 'status' is missing in type 'AbstractHttpAdapter<TServer, TRequest, TResponse>' but required in type 'HttpServer<TRequest, TResponse>'.

5 export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {
~~~~~~~~~~~~~~~~~~~

    node_modules/@nestjs/common/interfaces/http/http-server.interface.d.ts:26:5
    26     status(response: any, statusCode: number): any;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'status' is declared here.

    node_modules/@nestjs/core/application-config.d.ts:2:39 - error TS2307: Cannot find module '@nestjs/common/interfaces/configuration-provider.interface'.

    2 import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    node_modules/@nestjs/core/guards/guards-context-creator.d.ts:3:39 - error TS2307: Cannot find module '@nestjs/common/interfaces/configuration-provider.interface'.

3 import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    node_modules/@nestjs/core/interceptors/interceptors-context-creator.d.ts:2:39 - error TS2307: Cannot find module '@nestjs/common/interfaces/configuration-provider.interface'.

2 import { ConfigurationProvider } from '@nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    node_modules/@nestjs/core/nest-application.d.ts:24:5 - error TS2416: Property 'getHttpAdapter' in type 'NestApplication' is not assignable to the same property in base type 'INestApplication'.
    Type '() => AbstractHttpAdapter<any, any, any>' is not assignable to type '() => HttpServer<any, any>'.
    Property 'status' is missing in type 'AbstractHttpAdapter<any, any, any>' but required in type 'HttpServer<any, any>'.

24     getHttpAdapter(): AbstractHttpAdapter;
~~~~~~~~~~~~~~

    node_modules/@nestjs/common/interfaces/http/http-server.interface.d.ts:26:5
26     status(response: any, statusCode: number): any;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'status' is declared here.


    Found 5 errors.

我正在使用tsc -p tsconfig.build.json 命令用tsconfig.build.json 构建它:

{
    "extends": "./tsconfig.json",
    "exclude": ["node_modules", "test", "**/*spec.ts"]
}

tsconfig.json:

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

我希望这个配置应该将 typescript 代码编译为 javascript,然后我将使用 node dist/main.js 命令运行。它实际上是这样做的。但我担心打字稿编译器错误。

【问题讨论】:

  • 请将您的错误粘贴到 StackOverflow 中。图片难以阅读,并阻止其他人提供帮助。你用的是什么启动命令?你是如何构建你的项目的?您如何测试部署?您要部署到哪里(如果您当前正在部署服务器)?
  • 抱歉,我以后会记住这一点。我已经编辑了问题。

标签: nestjs


【解决方案1】:

不确定没有代码,但曾在嵌套核心包中遇到过类似的不匹配。查看package.json 并确保所有@nest 软件包具有相同的版本,因为有时即使不是主要版本,它们也会有“重大”更改。

举个抽象的例子,在构建生产环境时,类似的事情给了我与core 相关的错误:

   "@nestjs/common": "6.6.0",  // notice the core/common does not match, it should be bumped
   "@nestjs/core": "6.6.2",

【讨论】:

  • 事实证明,这确实是问题所在。尽管现在我使用nestjs 无法解决猫鼬@InjectModel 依赖项。但这是另一个问题。
猜你喜欢
  • 2016-09-18
  • 1970-01-01
  • 1970-01-01
  • 2018-11-29
  • 2016-03-12
  • 2019-05-26
  • 2011-10-23
  • 2023-03-22
  • 2023-02-01
相关资源
最近更新 更多