PersistenceManager:default not resolved - Nest.js version 8
See original GitHub issueHi there, thanks for this great library, I’m trying to use it in my nest project in a leverage of Neo4j but I’ve some issues.
First I think the sample needs to be updated as they are importing stuff from nested path instead of @liberation-data/drivine
and can lead in the same issue as #47.
Same import is described in the user guide: https://drivine.org/guide/#/quick-start
After fixing this issue, I’m still facing an error with PersistenceManager
:
[Nest] 5393 - 2021-08-21, 11:24:01 a.m. ERROR [ExceptionHandler] Nest can't resolve dependencies of the UsersRepository (?, CYPHER:/[CENSORED]/dist/src/users/cyphers/create.cypher, CYPHER:/[CENSORED]/dist/src/users/cyphers/users.cypher, CYPHER:/[CENSORED]/dist/src/users/cyphers/userById.cypher). Please make sure that the argument PersistenceManager:default at index [0] is available in the UsersModule context.
Potential solutions:
- If PersistenceManager:default is a provider, is it part of the current UsersModule?
- If PersistenceManager:default is exported from a separate @Module, is that module imported within UsersModule?
@Module({
imports: [ /* the Module containing PersistenceManager:default */ ]
})
Error: Nest can't resolve dependencies of the UsersRepository (?, CYPHER:/[CENSORED]/dist/src/users/cyphers/create.cypher, CYPHER:/[CENSORED]/dist/src/users/cyphers/users.cypher, CYPHER:/[CENSORED]/dist/src/users/cyphers/userById.cypher). Please make sure that the argument PersistenceManager:default at index [0] is available in the UsersModule context.
Potential solutions:
- If PersistenceManager:default is a provider, is it part of the current UsersModule?
- If PersistenceManager:default is exported from a separate @Module, is that module imported within UsersModule?
@Module({
imports: [ /* the Module containing PersistenceManager:default */ ]
})
Here is a look on my files:
app.module.ts
import { Module } from '@nestjs/common';
import {
DatabaseRegistry,
DrivineModule,
DrivineModuleOptions,
} from '@liberation-data/drivine';
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigModule } from '@nestjs/config';
import { join } from 'path';
import { CognitoModule } from 'src/cognito/cognito.module';
import { AuthModule } from 'src/auth/auth.module';
import { UsersModule } from 'src/users/users.module';
import { validate } from 'src/configuration/env.validation';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
validate,
}),
DrivineModule.withOptions(<DrivineModuleOptions>{
connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv('NEO4J')],
}),
CognitoModule.fromEnv(),
GraphQLModule.forRoot({
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
sortSchema: true,
debug: process.env.NODE_ENV === 'development',
playground: process.env.NODE_ENV === 'development',
}),
AuthModule,
UsersModule,
],
})
export class AppModule {}
users.module.ts
import { Module } from '@nestjs/common';
import { UsersService } from 'src/users/users.service';
import { UsersResolver } from 'src/users/users.resolver';
import { UsersRepository } from 'src/users/users.repository';
@Module({
providers: [UsersService, UsersResolver, UsersRepository],
exports: [UsersService],
})
export class UsersModule {}
users.repository.ts
import { Injectable } from '@nestjs/common';
import {
CypherStatement,
InjectCypher,
InjectPersistenceManager,
PersistenceManager,
QuerySpecification,
Transactional,
} from '@liberation-data/drivine';
import { classToPlain } from 'class-transformer';
import { UserEntity } from 'src/users/entities/user.entity';
@Injectable()
export class UsersRepository {
constructor(
@InjectPersistenceManager() readonly persistenceManager: PersistenceManager,
@InjectCypher(__dirname, 'cyphers/create')
readonly createCypher: CypherStatement,
@InjectCypher(__dirname, 'cyphers/users')
readonly usersCypher: CypherStatement,
@InjectCypher(__dirname, 'cyphers/userById')
readonly userByIdCypher: CypherStatement,
) {}
@Transactional()
async create(user: UserEntity) {
const spec = new QuerySpecification<UserEntity>()
.withStatement(this.createCypher)
.bind([classToPlain(user)]);
return this.persistenceManager.query(spec);
}
@Transactional()
async all() {
const spec = new QuerySpecification<UserEntity>().withStatement(
this.usersCypher,
);
return this.persistenceManager.query(spec);
}
@Transactional()
async findById(id: string) {
const spec = new QuerySpecification<UserEntity>()
.withStatement(this.usersCypher)
.bind({ id });
return this.persistenceManager.getOne(spec);
}
}
Anyone facing the same issue ?
I think it may be related to nest version, as I’m using the following one:
Extract of package.json
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.0.1",
"@nestjs/core": "^8.0.0",
"@nestjs/graphql": "^8.0.2",
"@nestjs/passport": "^8.0.1",
"@nestjs/platform-express": "^8.0.0",
I don’t really want to downgrade my nest version to get it working.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Common errors - FAQ - A progressive Node.js framework
During your development with NestJS, you may encounter various errors as you learn the framework. "Cannot resolve dependency" error#. Probably the most common ......
Read more >Nest can't resolve dependencies of the [ServiceName] #4457
My answer: It is a provider, but it's not part of the current module. It's a provider from the ConsentModule. See ConsentModule definition....
Read more >NestJS Error: "Nest can't resolve dependencies of the ...
In my nestjs application, I have a User and Auth module. ... I am getting the dependencies resolution error (See the last part)....
Read more >Getting started with continuous integration for Nest.js APIs
Learn how to build RESTful APIs with Nest.js, a Node.js framework built with TypeScript, and automate testing using CircleCI.
Read more >@nestjs/core - npm
A progressive Node.js framework for building efficient and scalable server-side applications. NPM Version Package License NPM Downloads ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok if anyone get there, I’ve just found the issue.
It’s not really well described in the quick-start, but as soon as you are providing a name to
DatabaseRegistry.buildOrResolveFromEnv('NEO4J')
. You need to reflect this one in the InjectPersistenceManager like that:@InjectPersistenceManager('NEO4J')
@dominiklippl Done. You now have write access.
THANK YOU for helping out!