Code Monkey home page Code Monkey logo

Comments (8)

kairauer avatar kairauer commented on May 14, 2024 3

To anyone else who gets a similar issue, I think this is related to this issue: nestjs/nest#528

from crud.

michaelyali avatar michaelyali commented on May 14, 2024 1

Yes, that was my point. And, in general, I think it has nothing to do with RepositoryService or with NestJs, but I think it's a TypeORM issue instead.

from crud.

michaelyali avatar michaelyali commented on May 14, 2024

Ok, could you please create a service as you normally do (not a RepositoryService, but just a dummy service) and inject it to your DoesUserAlreadyExist. And tell me if you still get this error. Thanks

from crud.

kairauer avatar kairauer commented on May 14, 2024

I created the following Service:

import { Injectable } from '@nestjs/common';

@Injectable()
export class UsersTestService {
  constructor() {
    console.log('UsersTestService');
  }
}

added the service to the UsersModule provider and injected the service in the DoesUserAlreadyExist validator:

...
constructor(private usersTestService: UsersTestService) {}
...

Everything works fine with this dummy service. Is there another way to execute repository methods?

from crud.

michaelyali avatar michaelyali commented on May 14, 2024

@kairauer
And if you inject TypeORM repository into your dummy service, would you be able to see that error in this case?

from crud.

kairauer avatar kairauer commented on May 14, 2024

I changed the dummy service:

import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { User } from './user.entity';

@Injectable()
export class UsersTestService {
  constructor(private userRepository: Repository<User>) {
    console.log('UsersTestService', this.userRepository);
  }
}

Now I get an error again:

Error: Nest can't resolve dependencies of the UsersTestService (?). Please make sure that the argument at index [0] is available in the UsersModule context.
    at Injector.lookupComponentInExports (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/@nestjs/core/injector/injector.js:144:19)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
    at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:51:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:804:11)
    at Object.<anonymous> (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/ts-node/src/bin.ts:157:12)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)

But I am pretty sure, that I injected a service (which injected the repository) in the past like its mentioned in the docs: https://docs.nestjs.com/recipes/sql-typeorm
Any ideas? And by the way, thanks for the fast response 👍

from crud.

michaelyali avatar michaelyali commented on May 14, 2024

Now you get another error, and it's not what I'm trying to get. We need to reproduce the first error.
So, as I can see, you're trying to inject repository in a wrong way. Please try this and tell me the result:

import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from './user.entity';

@Injectable()
export class UsersTestService {
  constructor(@InjectRepository(User) private userRepository: Repository<User>) {
    console.log('UsersTestService', this.userRepository);
  }
}

from crud.

kairauer avatar kairauer commented on May 14, 2024

Yes, you are right, that wasn't the right way to inject the repository. I tried it with your solution, now I get nearly the same error as in my first post:

TypeError: Cannot read property 'name' of undefined
    at Object.getRepositoryToken (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js:8:22)
    at Object.exports.InjectRepository (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.js:5:72)
    at Object.<anonymous> (/Users/kai/Development/NodeJS/crud/integration/typeorm/src/users/test.service.ts:8:16)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Module.m._compile (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/kai/Development/NodeJS/crud/integration/typeorm/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)

So, it seems like it's not caused by the extended RepositoryService class, right? I could fork the repo and implement the changes I did, if that helps to debug this.

from crud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.