Skip to content

Providers doesn't exist in the current context #32

Description

@tsaqifrazin1

Screen Shot 2023-02-06 at 23 14 08

Activity

  1. alphamikle commented on Feb 6, 2023

    @alphamikle
    Owner

    Hello @tsaqifrazin1, please, try the updated version 9.1.1

  2. tsaqifrazin1 commented on Feb 7, 2023

    @tsaqifrazin1
    Author

    Hi @alphamikle, Thanks for replying. I've updated the version but the error still exists

  3. tsaqifrazin1 commented on Feb 7, 2023

    @tsaqifrazin1
    Author

    Maybe this information help
    this is my package.json

    "dependencies": {
        "@nestjs/common": "^9.0.0",
        "@nestjs/config": "^2.2.0",
        "@nestjs/core": "^9.0.0",
        "@nestjs/passport": "^9.0.1",
        "@nestjs/platform-express": "^9.0.0",
        "@nestjs/swagger": "^6.1.2",
        "@nestjs/typeorm": "^9.0.1",
        "axios": "^1.3.2",
        "class-transformer": "^0.5.1",
        "class-validator": "^0.13.2",
        "compression": "^1.7.4",
        "dotenv": "^16.0.3",
        "dotenv-cli": "^7.0.0",
        "express-rate-limit": "^6.6.0",
        "helmet": "^6.0.1",
        "morgan": "^1.10.0",
        "nest-transact": "^9.1.1",
        "passport-jwt": "^4.0.1",
        "pg": "^8.8.0",
        "reflect-metadata": "^0.1.13",
        "request-context": "^2.0.0",
        "rimraf": "^3.0.2",
        "rxjs": "^7.2.0",
        "typeorm": "^0.3.9",
        "typeorm-transactional": "^0.4.1",
        "typeorm-transactional-cls-hooked": "^0.1.21"
      },
      "devDependencies": {
        "@nestjs/cli": "^9.0.0",
        "@nestjs/schematics": "^9.0.0",
        "@nestjs/testing": "^9.0.0",
        "@types/express": "^4.17.13",
        "@types/jest": "28.1.8",
        "@types/node": "^16.0.0",
        "@types/supertest": "^2.0.11",
        "@typescript-eslint/eslint-plugin": "^5.0.0",
        "@typescript-eslint/parser": "^5.0.0",
        "eslint": "^8.0.1",
        "eslint-config-prettier": "^8.3.0",
        "eslint-plugin-prettier": "^4.0.0",
        "jest": "28.1.3",
        "prettier": "^2.3.2",
        "source-map-support": "^0.5.20",
        "supertest": "^6.1.3",
        "ts-jest": "28.0.8",
        "ts-loader": "^9.2.3",
        "ts-node": "^10.0.0",
        "tsconfig-paths": "4.1.0",
        "typescript": "^4.7.4"
      },
    

    this is my controller

    @Controller('category')
    @ApiTags('category')
    @UseInterceptors(TransformResponseInterceptor)
    export class CategoryController {
      constructor(
        private readonly categoryService: CategoryService,
        private readonly dataSource: DataSource,
      ) {}
      @Get()
      @ApiBearerAuth()
      @UseGuards(JwtAuthGuard, RolesNameTypeGuard)
      @RolesNameType('kasiDalpersmil')
      async readAllCategories() {
        const category = await this.dataSource.transaction(async(manager) => {
          return  await this.categoryService.getCategories({});
        })
        return {
          message: 'Success read all category',
          data: category,
        };
      }
    }
    

    this is my service

    @Injectable
    export class CategoryService extends TransactionFor<CategoryService> {
      constructor(
        @InjectRepository(CategoryEntity)
        private readonly categoryRepository: Repository<CategoryEntity>,
        moduleRef: ModuleRef,
      ) {
        super(moduleRef);
      }
      ...
      ...
      ...
    }
    
  4. alphamikle commented on Feb 8, 2023

    @alphamikle
    Owner

    Hey @tsaqifrazin1! It seems that you did not use TransactionFor<T>` method .withTransaction. U just call

    return  await this.categoryService.getCategories({});

    instead of

    return  await this.categoryService.withTransaction(manager).getCategories({});
  5. tsaqifrazin1 commented on Feb 8, 2023

    @tsaqifrazin1
    Author

    I'm sorry, I give you the wrong code.

    @Controller('category')
    @ApiTags('category')
    @UseInterceptors(TransformResponseInterceptor)
    export class CategoryController {
      constructor(
        private readonly categoryService: CategoryService,
        private readonly dataSource: DataSource,
      ) {}
      @Get()
      @ApiBearerAuth()
      @UseGuards(JwtAuthGuard, RolesNameTypeGuard)
      @RolesNameType('kasiDalpersmil')
      async readAllCategories() {
        const category = await this.dataSource.transaction(async(manager) => {
          return this.categoryService.withTransaction(manager).getCategories({});
        })
        return {
          message: 'Success read all category',
          data: category,
        };
      }
    }
    

    my code is like this

  6. devmarcellus commented on Feb 8, 2023

    @devmarcellus

    Hi ,

    The same error was reproduced on my side, while it worked perfectly after an npm install it no longer worked
    I updated to the latest version but it still gives this error.

    Error: Nest could not find Repository element (this provider does not exist in the current context)

  7. RazvanStetcu commented on Feb 13, 2023

    @RazvanStetcu

    Same happens for me. Works fine locally but I got the same error on production environment

  8. mabalashov commented on Feb 16, 2023

    @mabalashov

    As a temporary solution. Downgrade packages nest/common and nest/core to version 9.2.1:

    "@nestjs/common": "9.2.1",
    "@nestjs/core": "9.2.1",
    

    Works for me

  9. tsaqifrazin1 commented on Feb 17, 2023

    @tsaqifrazin1
    Author

    As a temporary solution. Downgrade packages nest/common and nest/core to version 9.2.1:

    "@nestjs/common": "9.2.1",
    "@nestjs/core": "9.2.1",
    

    Works for me

    Works for me too

  10. Fusix commented on Mar 19, 2023

    @Fusix

    Hey this is a possible workaround but not a solution. With newer versions of NestJS we get the above error. Is there an updated solution on this topic?

  11. alphamikle commented on Mar 19, 2023

    @alphamikle
    Owner

    Hey @Fusix. I have very limited resources at the moment and cannot deal with the problem. If you can solve this issue with a PR, I will accept it. That way you will help yourself and others.

  12. cccabdalla commented on Apr 25, 2023

    @cccabdalla

    i am also here reporting the same issue which i am still struggling with !

    Any reliable fix ?

  13. cccabdalla commented on Apr 25, 2023

    @cccabdalla

    9.2.1

    thanks, also worked for me but would prefer better fix to be done if possible.

    for me, No downgrading but upgrading from "9.0.0" to "9.2.1" !

    also wondering how on earth "@nestjs/common" and "@nestjs/core" had "9.0.0" version in the first place for project which was created 2 hours ago !

  14. maxpeterson commented on Feb 21, 2024

    @maxpeterson
    Contributor

    Having dug into this a little it seems that Nest is not finding the Repository dependencies anymore (dependency = this.moduleRef.get(param, { strict: false });). Using the repository token (string) seems to work so it is as if the Repository class no longer matches.

    We have abandoned using nest_transact, but if someone has time I would suggest trying to create a failing NestJS example without using nest_transact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions