英文:
error TS2305: Module '"@nestjs/typeorm"' has no exported member 'getRepositoryToken'
问题
I've been messing around with packages version of Nestjs and TypeOrm, and I have fallen in a rabbit hole of TS errors.
我一直在尝试使用Nestjs和TypeOrm的包版本,但陷入了TS错误的困境。
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和nestjs/typeorm版本为:
"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"
}
英文:
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"
},
答案1
得分: 1
最有可能的原因是你从GitHub获取nestjs/typeorm(我认为这是导入方式的一种情况),但它可能没有正确的文件,与package.json的主要引用不符,因为它是ts源代码而不是js编译代码。
实际上,从npm安装@nestjs/typeorm
,应该没有问题。
英文:
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
答案2
得分: -1
很好地发现了 @alex-wayne !
通过运行 yarn add @nestjs/typeorm@latest
来获取一个经典的版本号,解决了我的问题,谢谢 🙏
英文:
Well spotted @alex-wayne !
A yarn add @nestjs/typeorm@latest fixed my issue by getting a classic version number, thanks 🙏
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论