【问题标题】:Module '"typeorm"' has no exported member 'DataSource' and 'DataSourceOptions'模块 '"typeorm"' 没有导出的成员 'DataSource' 和 'DataSourceOptions'
【发布时间】:2022-07-13 13:57:45
【问题描述】:

Module '"typeorm"' has no exported member 'DataSource'.Module '"typeorm"' has no exported member 'DataSourceOptions'. nest build 时出现错误。

在 npm install 之后,我从命令行使用 nest buildcommand 构建了我的 nestjs 应用程序,但我收到了这些错误。

typeorm 版本是“^0.2.25”,而“@nestjs/typeorm”:“^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,
};

【问题讨论】:

  • 显示你的 tsconfig.json
  • @DaveMeehan 我已经更新了问题并添加了 tsconfig.json。
  • 你也可以显示你的 orm 配置吗?
  • @n1md7 我已经添加了 orm 配置。
  • afaik DataSource在v0.3中引入,你确定安装的TypeORM版本肯定是v0.2.25?

标签: node.js npm nestjs typeorm


【解决方案1】:

我通过指定固定包版本修复了这个错误:

"@nestjs/typeform": "8.0.2", "typeform": "0.2.45",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-20
    • 2017-05-07
    • 2017-08-18
    • 1970-01-01
    • 2023-03-04
    • 2021-07-08
    • 2017-09-09
    相关资源
    最近更新 更多