Grapeoff
@Grapeoff
В чём концепция...?

Почему моя библиотека работает только при установке из NPM?

Делаю библиотеку для NestJS, и чтобы её протестировать, я создал проект и прилинковал эту библиотеку при помощи yarn link, но когда я запускаю тестовый проект, он постоянно падает из-за того что Nest не может получить никакие зависимости. При этом если отправить эту библиотеку в NPM и скачать оттуда, то всё работает замечательно.
В чём может быть проблема?

package.json библиотеки:

{
    "name": "kindagoose",
    "version": "1.0.10",
    "description": "Integrate Typegoose with NestJS!",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",
    "keywords": [
        "nest",
        "nestjs",
        "mongoose",
        "typegoose",
        "mongo",
        "mongodb"
    ],
    "repository": {
        "url": "https://github.com/GrapeoffJS/kindagoose",
        "type": "git"
    },
    "author": "Dmitriy Grape <grapeoff.official@gmail.com>",
    "engines": {
        "node": ">=16.16.0"
    },
    "bugs": {
        "url": "https://github.com/GrapeoffJS/kindagoose/issues",
        "email": "grapeoff.official@gmail.com"
    },
    "scripts": {
        "build": "rimraf dist && tsc -p tsconfig.json",
        "build:dev": "rimraf dist && tsc --watch -p tsconfig.json",
        "prepare": "yarn build"
    },
    "license": "GPL-3.0-only",
    "private": false,
    "devDependencies": {
        "@nestjs/common": "^9.0.7",
        "@nestjs/core": "^9.0.7",
        "@typegoose/typegoose": "^9.11.0",
        "mongoose": "^6.5.0",
        "reflect-metadata": "^0.1.13",
        "rxjs": "^7.5.6",
        "@types/mongoose": "^5.11.97",
        "@typescript-eslint/eslint-plugin": "^5.31.0",
        "@typescript-eslint/parser": "^5.31.0",
        "eslint": "^8.20.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-plugin-import": "^2.26.0",
        "eslint-plugin-prettier": "^4.2.1",
        "eslint-plugin-security": "^1.5.0",
        "eslint-plugin-simple-import-sort": "^7.0.0",
        "eslint-plugin-sonarjs": "^0.14.0",
        "eslint-plugin-unicorn": "^43.0.2",
        "prettier": "^2.7.1",
        "rimraf": "^3.0.2",
        "typescript": "^4.7.4"
    },
    "peerDependencies": {
        "@nestjs/common": "^9.0.0",
        "@nestjs/core": "^9.0.0",
        "@typegoose/typegoose": "^9.11.0",
        "mongoose": "^6.5.0",
        "reflect-metadata": "^0.1.13",
        "rxjs": "^7.5.6"
    }
}

Одна из ошибок при запуске проекта (если решить её, то он всё равно упадёт, но уже с какой-нибудь другой ошибкой):

ERROR [ExceptionHandler] Nest can't resolve dependencies of the KindagooseCoreModule (KindagooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the KindagooseCoreModule context.

Potential solutions:
- If ModuleRef is a provider, is it part of the current KindagooseCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within KindagooseCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

Error: Nest can't resolve dependencies of the KindagooseCoreModule (KindagooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the 
KindagooseCoreModule context.

Potential solutions:
- If ModuleRef is a provider, is it part of the current KindagooseCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within KindagooseCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

    at Injector.lookupComponentInParentModules (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:241:19)
    at Injector.resolveComponentInstance (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:194:33)
    at resolveParam (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:116:38)
    at async Promise.all (index 1)
    at Injector.resolveConstructorParams (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:131:27)
    at Injector.loadInstance (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:57:13)
    at Injector.loadProvider (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\injector.js:84:9)
    at async Promise.all (index 0)
    at InstanceLoader.createInstancesOfProviders (D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\instance-loader.js:44:9)
    at D:\WebStorm\kindagoose-test\node_modules\@nestjs\core\injector\instance-loader.js:29:13


Полный исходный код проекта: https://github.com/GrapeoffJS/kindagoose
  • Вопрос задан
  • 216 просмотров
Пригласить эксперта
Ответы на вопрос 1
402d
@402d
начинал с бейсика на УКНЦ в 1988
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы