Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nest can't resolve dependencies of the EntityModel #10

Open
stimka opened this issue Oct 31, 2019 · 1 comment
Open

Nest can't resolve dependencies of the EntityModel #10

stimka opened this issue Oct 31, 2019 · 1 comment

Comments

@stimka
Copy link

stimka commented Oct 31, 2019

I'm submitting a...


[ ] Regression 
[x ] Bug report
[ ] Feature request
[ ] Documentation issue or request

Current behavior

I used this tutorial: https://github.com/ifaim/nestjs-express-cassandra#using-repository, and get an error.


Nest can't resolve dependencies of the TokenEntityModel (?). Please make sure that the argument f at index [0] is available in the ExpressCassandraModule context.

Potential solutions:
- If f is a provider, is it part of the current ExpressCassandraModule?
- If f is exported from a separate @Module, is that module imported within ExpressCassandraModule?
  @Module({
    imports: [ /* the Module containing f */ ]
  })
 +21ms
Error: Nest can't resolve dependencies of the TokenEntityModel (?). Please make sure that the argument f at index [0] is available in the ExpressCassandraModule context.

Potential solutions:
- If f is a provider, is it part of the current ExpressCassandraModule?
- If f is exported from a separate @Module, is that module imported within ExpressCassandraModule?
  @Module({
    imports: [ /* the Module containing f */ ]
  })

    at Injector.lookupComponentInExports (/home/user/ss/token-service/node_modules/@nestjs/core/injector/injector.js:183:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at Object. (/home/user/ss/token-service/node_modules/ts-node/src/bin.ts:154:12)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Reproduction of the problem with instructions

My code identical with that tutorial and i used it for microservice:


async function bootstrap() {
	console.log(config.rmq.urls, config.rmq.queue);
	const app = await NestFactory.createMicroservice(await AppModule.forRoot());

	await app.listenAsync();
}

export class AppModule {
	static async forRoot(): Promise {
		const exM = ExpressCassandraModule.forFeature([TokenEntity]);

		return {
			module: AppModule,
			imports: [
				exM,
			],
			providers: [{
				provide: 'ITokenService',
				useClass: TokenService,
			}],
			controllers: [TokenController],
		};
	}
}

@Injectable()
export class TokenService implements ITokenService {
	constructor(
		@InjectRepository(TokenEntity) private readonly tokenRepository: Repository,
	) {}

	insert(token): Observable {
		return this.tokenRepository.save(token);
	}
}

@Entity({
	table_name: 'project_tokens',
	key: ['id'],
})
export class TokenEntity {
	@Column({ type: 'uuid' })
	id: any;

	@Column({
		type: DataType.Varchar,
	})
	projecttoken: string;
}

Environment


Nest version: 6.0.0
Nest microservices version: 6.8.5

 
For Tooling issues:
- Node version: 10.16.3
- Platform: Linux

Others:
Ubuntu 18.04.3

@vudc
Copy link

vudc commented Sep 30, 2021

try change ExpressCassandraModule.forFeature([TokenEntity]) to ExpressCassandraModule.forFeature([TokenEntity], 'your-connection-name')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants