NodeJS 模块“typeorm”没有导出的成员“DataSource”和“DataSourceOptions”

jxct1oxe  于 2022-12-12  发布在  Node.js
关注(0)|答案(3)|浏览(436)

nest build时,我得到错误Module '"typeorm"' has no exported member 'DataSource'.Module '"typeorm"' has no exported member 'DataSourceOptions'.
在npm安装后,我从命令行使用nest build命令构建了我的nestjs应用程序,但是我得到了这些错误。
类型格式版本为“^0.2.25”,而“@nestjs/类型格式”:“^8.0.2”,
不知道为什么会这样。
tsconfig.json

  1. {
  2. "compilerOptions": {
  3. "module": "commonjs",
  4. "declaration": true,
  5. "removeComments": true,
  6. "emitDecoratorMetadata": true,
  7. "experimentalDecorators": true,
  8. "allowSyntheticDefaultImports": true,
  9. "target": "es2019",
  10. "sourceMap": true,
  11. "outDir": "./dist",
  12. "baseUrl": "./src",
  13. "incremental": true,
  14. "typeRoots": ["types", "node_modules/@types"],
  15. "strict": true,
  16. "esModuleInterop": true,
  17. "resolveJsonModule": true,
  18. "useUnknownInCatchVariables": false
  19. },
  20. "exclude": ["node_modules", "scripts", "dist"]
  21. }

ormconfig.ts

  1. const DATABASE_TYPE = process.env.DATABASE_TYPE || 'postgres';
  2. const DATABASE_URL = process.env.DATABASE_URL;
  3. const DATABASE_SSL =
  4. process.env.DATABASE_SSL !== undefined ? process.env.DATABASE_SSL === 'true' : true;
  5. const DATABASE_SSL_CA = process.env.DATABASE_SSL_CA;
  6. const root = __dirname;
  7. export default {
  8. type: DATABASE_TYPE,
  9. url: DATABASE_URL,
  10. schema: 'qcxapp',
  11. entities: [`${root}/**/*.entity.{js,ts}`, `${root}/**/*.model.{js,ts}`],
  12. migrations: [`${root}/database/migrations/*.{js,ts}`],
  13. synchronize: false,
  14. cli: {
  15. migrationsDir: `${root}/database/migrations`,
  16. },
  17. seeds: [`${root}/**/*.seed.{js,ts}`],
  18. factories: [`${root}/**/*.factory.{js,ts}`],
  19. keepConnectionAlive: true,
  20. ssl: DATABASE_SSL_CA ? { ca: DATABASE_SSL_CA, rejectUnauthorized: false } : DATABASE_SSL,
  21. };
vaj7vani

vaj7vani1#

我通过指定修复的软件包版本修复了此错误:

  1. "@nestjs/typeorm": "8.0.2",
  2. "typeorm": "0.2.45",
kzmpq1sx

kzmpq1sx2#

我通过删除typeorm然后再次添加来解决这个问题。使用以下命令:

  1. yarn remove typeorm

以后

  1. yarn add typeorm
0mkxixxg

0mkxixxg3#

如果typeorm版本不是8.0.2,nest inpx nest i表示服务器)是否查找typeorm版本?

  1. yarn remove @nestjs/typeorm

然后

  1. yarn add @nestjs/typeorm@8.0.2

如果typeorm版本为8.0.2,则使用nest i(服务器为npx nest i)再次检查嵌套信息,问题应该消失

相关问题