Reputation: 1999
I've been messing around with packages version of Nestjs and TypeOrm, and I have fallen in a rabbit hole of TS errors.
I've solved many but one is persistant and I can't figure out how to solve it:
src/workout/workout.module.ts:2:10 - error TS2305: Module '"@nestjs/typeorm"' has no exported member 'getRepositoryToken'.
2 import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm'
~~~~~~~~~~~~~~~~~~
src/workout/workout.module.ts:2:30 - error TS2305: Module '"@nestjs/typeorm"' has no exported member 'TypeOrmModule'.
2 import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm'
The source code being:
import { Module } from '@nestjs/common'
import { getRepositoryToken, TypeOrmModule } from '@nestjs/typeorm'
import { WorkoutResolver } from './workout.resolver'
import { WorkoutService } from './workout.service'
import { TypeOrmExerciseTemplateRepository } from '../exercise/repositories/type-orm-exercise-template.repository'
import { TypeOrmWorkoutRepository } from './repositories/workout.typeorm.repository'
import { TypeOrmExerciseRepository } from '../exercise/repositories/type-orm-exercise.repository'
import { WORKOUT_REPOSITORY } from './repositories/workout.repository.interface'
import { EXERCISE_TEMPLATE_REPOSITORY } from '../exercise/repositories/exercise-template-repository.interface'
import { EXERCISE_REPOSITORY } from '../exercise/repositories/exercise-repository.interface'
import { TypeOrmSessionRepository } from '../session/repositories/session.typeorm.repository'
import { FillWorkoutWithExercisesUseCase } from './use-cases/fill-workout-with-exercises.use-case'
import { PROGRAM_REPOSITORY } from '../program/repositories/program-repository.interface'
import { TypeOrmProgramRepository } from '../program/repositories/type-orm-program.repository'
@Module({
imports: [
TypeOrmModule.forFeature([
TypeOrmExerciseTemplateRepository,
TypeOrmExerciseRepository,
TypeOrmWorkoutRepository,
TypeOrmSessionRepository,
TypeOrmProgramRepository,
]),
],
providers: [
{
provide: WORKOUT_REPOSITORY,
useExisting: getRepositoryToken(TypeOrmWorkoutRepository),
},
{
provide: EXERCISE_REPOSITORY,
useExisting: getRepositoryToken(TypeOrmExerciseRepository),
},
{
provide: EXERCISE_TEMPLATE_REPOSITORY,
useExisting: getRepositoryToken(TypeOrmExerciseTemplateRepository),
},
{
provide: PROGRAM_REPOSITORY,
useExisting: getRepositoryToken(TypeOrmProgramRepository),
},
WorkoutResolver,
WorkoutService,
FillWorkoutWithExercisesUseCase,
],
})
export class WorkoutModule {}
My typeorm and nestjs/typeorm version are:
"typeorm": "^0.3.12",
"@nestjs/typeorm": "nestjs/typeorm",
The full dependencies:
"dependencies": {
"@apollo/gateway": "^0.51.0",
"@nestjs/apollo": "^10.0.19",
"@nestjs/common": "^7.6.15",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^7.6.15",
"@nestjs/graphql": "^10.0.21",
"@nestjs/jwt": "^8.0.0",
"@nestjs/passport": "^8.2.1",
"@nestjs/platform-express": "^7.6.15",
"@nestjs/typeorm": "nestjs/typeorm",
"@types/bcrypt": "^5.0.0",
"@types/passport-jwt": "^3.0.6",
"apollo-server-express": "^2",
"bcrypt": "^5.0.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"dotenv": "^16.0.1",
"env-var": "^7.3.0",
"faker": "^5.5.3",
"graphql": "^15.8.0",
"graphql-tools": "^8.3.3",
"knex": "^2.2.0",
"mysql2": "^2.3.3",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7",
"ts-morph": "^15.1.0",
"typeorm": "^0.3.12"
},
Upvotes: 0
Views: 706
Reputation: 70131
Most likely it's the fact that you're pulling nestjs/typeorm from GitHub (I believe that's what happens with that kind of import) which doesn't end up having the proper file that the main of the package.json references because it's the ts source code and not the js compiled code
Actually install @nestjs/typeorm
from npm and it should be fine
Upvotes: 1
Reputation: 1999
Well spotted @alex-wayne !
A yarn add @nestjs/typeorm@latest fixed my issue by getting a classic version number, thanks 🙏
Upvotes: -1