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

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

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

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2019",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "incremental": true,
    "typeRoots": ["types", "node_modules/@types"],
    "strict": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "useUnknownInCatchVariables": false
  },
  "exclude": ["node_modules", "scripts", "dist"]
}

ormconfig.ts

const DATABASE_TYPE = process.env.DATABASE_TYPE || 'postgres';
const DATABASE_URL = process.env.DATABASE_URL;

const DATABASE_SSL =
  process.env.DATABASE_SSL !== undefined ? process.env.DATABASE_SSL === 'true' : true;
const DATABASE_SSL_CA = process.env.DATABASE_SSL_CA;

const root = __dirname;

export default {
  type: DATABASE_TYPE,
  url: DATABASE_URL,
  schema: 'qcxapp',
  entities: [`${root}/**/*.entity.{js,ts}`, `${root}/**/*.model.{js,ts}`],
  migrations: [`${root}/database/migrations/*.{js,ts}`],
  synchronize: false,
  cli: {
    migrationsDir: `${root}/database/migrations`,
  },
  seeds: [`${root}/**/*.seed.{js,ts}`],
  factories: [`${root}/**/*.factory.{js,ts}`],
  keepConnectionAlive: true,
  ssl: DATABASE_SSL_CA ? { ca: DATABASE_SSL_CA, rejectUnauthorized: false } : DATABASE_SSL,
};
vaj7vani

vaj7vani1#

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

"@nestjs/typeorm": "8.0.2",
"typeorm": "0.2.45",
kzmpq1sx

kzmpq1sx2#

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

yarn remove typeorm

以后

yarn add typeorm
0mkxixxg

0mkxixxg3#

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

yarn remove @nestjs/typeorm

然后

yarn add @nestjs/typeorm@8.0.2

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

相关问题