【问题标题】:Dependencies not found for service when using npm link and npm run start:dev使用 npm link 和 npm run start:dev 时找不到服务的依赖项
【发布时间】:2021-09-12 10:43:20
【问题描述】:

我有一个正在本地开发的模块。当我在模块中使用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"
  }
}

【问题讨论】:

  • 你有没有找到一种方法来完成这项工作?
  • 我不记得了,我不再有权访问该存储库。

标签: express service dependency-injection request nestjs


【解决方案1】:

我不再有权访问该存储库,所以我无法告诉您我是修复它还是在本地复制它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 2014-08-24
    • 2016-08-29
    • 2019-11-16
    相关资源
    最近更新 更多