question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PersistenceManager:default not resolved - Nest.js version 8

See original GitHub issue

Hi 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:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
magrinjcommented, Aug 21, 2021

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')

0reactions
jasperbluescommented, Oct 7, 2021

@dominiklippl Done. You now have write access.

  • If you want to change code : Please send a pull request
  • To edit the wiki: You can do that directly. Afterwards can you please let me know, so I can review?
  • If you want to be acknowledged as a contributor on the website, can you send a photo/short bio to jasper@liberation-data.com

THANK YOU for helping out!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found