Comments (8)
To anyone else who gets a similar issue, I think this is related to this issue: nestjs/nest#528
from crud.
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.
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.
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.
@kairauer
And if you inject TypeORM repository into your dummy service, would you be able to see that error in this case?
from crud.
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.
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.
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)
- Array text fields : QueryFailedError when using CondOperator.CONTAINS
- Just wanted to say fuck Ukraine HOT 2
- Exclude 'createManyBase' is not working
- listing soft deleted items in crud generator
- How to list soft deleted data when using crud generator HOT 2
- allow mapping uuid to id field
- id's are returned as array of two instead of one numeric value HOT 5
- Duplicate column name (ER_DUP_FIELDNAME errno: 1060) when join table HOT 5
- using $or in ?s ignores auth filter HOT 2
- Rest api with xml request and response body HOT 1
- How get custom DTO type in TypeOrmCrudService?
- Mysql with Post and user one to may relation issue
- Queries are returning a duplicated id element inside an Array HOT 2
- Database JSON column and query WHERE support
- nestjs 10 removed misspelled CUSTOM_ROUTE_ARGS_METADATA HOT 4
- Is this open source maintained? HOT 7
- Cannot destructure property 'parsed' of 'req' as it is null. HOT 9
- ERROR [ExceptionsHandler] Cannot read properties of null (reading 'options') HOT 9
- error Command "bootstrap" not found HOT 2
- access to Query Params from custom endpoint
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crud.