使用 npm 链接和 npm 运行时找不到服务的依赖项 start:dev



我有一个模块,我正在本地开发。 当我在模块中使用npm link然后在我的嵌套项目中使用npm link myModule然后npm run start:dev我的项目无法启动此错误。Error: Nest can't resolve dependencies of the AuditLogService (?). Please make sure that the argument at index [0] is available in the AppModule context.但是,当我发布模块并使用标准npm i时,一切正常。
我尝试过的事情:

  • 服务/提供者已正确添加到app.module.ts的提供者
  • 确保 package.json 中的常见依赖项具有相同的版本。
  • npm i myModule使我发布后一切正常。

思潮:

  • 我的服务适用于请求,但在启动期间失败,这是罪魁祸首吗?

工件:

  • 启动脚本"start:dev": "ts-node-dev --inspect --require tsconfig-paths/register --require dotenv/config server.ts"
  • 服务:

import { transformAndValidate } from 'class-transformer-validator';
import { Inject, Injectable, Scope } from '@nestjs/common';
// @ts-ignore
import { Request } from 'express';
import { REQUEST } from '@nestjs/core';
import { DFDHeaders, AuditLogEntry } from '../dtos';
import axios, { AxiosResponse, AxiosError } from 'axios';
import _ from 'lodash';
// @ts-ignore
import logger from 'dfd-logger';
import { AuditLogResponse } from '../types/audit-log';
@Injectable({ scope: Scope.REQUEST })
export class Service {
constructor(@Inject(REQUEST)
{
protocol,
hostname,
originalUrl,
headers
}: Partial<Request>) {
...
}
...
}
  • 依赖:
"dependencies": {
"@nestjs/common": "^6.3.2",
"@nestjs/core": "^6.3.2",
"@nestjs/passport": "^6.1.0",
"@nestjs/platform-express": "^6.0.4",
"@nestjs/swagger": "^3.1.0",
"@types/chance": "^1.0.4",
"@types/lodash": "^4.14.133",
"@types/passport": "^1.0.0",
"chance": "^1.0.18",
"class-transformer": "^0.2.3",
"class-transformer-validator": "^0.7.1",
"class-validator": "^0.9.1",
"dotenv": "^8.0.0",
"lodash": "^4.17.11",
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"reflect-metadata": "0.1.13",
"rxjs": "6.4.0",
"swagger-ui-express": "^4.0.7"
},
"devDependencies": {
"@nestjs/testing": "6.1.1",
"@types/express": "4.16.1",
"@types/jest": "24.0.11",
"@types/nock": "^10.0.3",
"@types/node": "11.13.4",
"@types/supertest": "2.0.7",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"concurrently": "^4.1.0",
"eslint-plugin-jest": "^22.13.6",
"eslint-plugin-prettier": "^3.1.0",
"eslint": "^6.1.0",
"husky": "^3.0.1",
"jest": "24.5.0",
"nock": "^10.0.6",
"prettier": "1.18.2",
"rimraf": "2.6.3",
"supertest": "4.0.2",
"ts-jest": "^24.0.2",
"ts-node-dev": "^1.0.0-pre.40",
"tsconfig-paths": "3.8.0",
"typescript": "3.5.2"
}
}

我不再有权访问该存储库,因此我无法告诉您是修复了它还是在本地重现了它。

最新更新