首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeORM - connectionNotFoundError

TypeORM - connectionNotFoundError
EN

Stack Overflow用户
提问于 2020-09-10 21:19:09
回答 1查看 375关注 0票数 1

我用Typescript + Typeorm + Express创建了一个项目。但是当run dev script返回这个错误时:connectionNotFoundError: Connection "default" was not found

我的ormconfig.json:

代码语言:javascript
复制
{
  "name": "default",
  "type": "postgres",
  "host": "localhost",
  "port": 5432,
  "username": "postgres",
  "password": "docker",
  "database": "clean-node-api",
  "synchronize": true,
  "logging": true,
  "entities": [
    "./src/infra/typeorm/entities/*.ts"
  ],
  "cli": {
    "migrationsDir": "./src/infra/typeorm/migrations"
  }
}

仓库链接:https://github.com/thuram/typescript-api-with-tdd

EN

回答 1

Stack Overflow用户

发布于 2020-09-11 10:43:31

我已经克隆了你的仓库并运行了你的代码我找到了回溯

代码语言:javascript
复制
ConnectionNotFoundError: Connection "default" was not found.
    at new ConnectionNotFoundError (/Users/lithium/develop/typescript-api-with-tdd/src/error/ConnectionNotFoundError.ts:8:9)
    at ConnectionManager.get (/Users/lithium/develop/typescript-api-with-tdd/src/connection/ConnectionManager.ts:40:19)
    at Object.getRepository (/Users/lithium/develop/typescript-api-with-tdd/src/index.ts:287:35)
    at new UserRepository (/Users/lithium/develop/typescript-api-with-tdd/src/infra/typeorm/repositories/UserRepository.ts:14:26)
    at Object.exports.makeCreateUser (/Users/lithium/develop/typescript-api-with-tdd/src/main/factories/useCases/user/CreateUserFactory.ts:5:26)
    at Object.exports.makeSignUpController (/Users/lithium/develop/typescript-api-with-tdd/src/main/factories/controllers/user/SignUpControllerFactory.ts:6:31)
    at Object.<anonymous> (/Users/lithium/develop/typescript-api-with-tdd/src/main/routes/SignUp.ts:5:26)
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Module._compile (/Users/lithium/develop/typescript-api-with-tdd/node_modules/source-map-support/source-map-support.js:547:25)
    at Module.m._compile (/private/var/folders/fx/7f3mc02s4lxbzjmzvw4cmknh0000gn/T/ts-node-dev-hook-1775948954112352.js:57:33)
[ERROR] 10:41:29 ConnectionNotFoundError: Connection "default" was not found.

UserRepository.ts:14:26)引发的错误,

代码语言:javascript
复制
  constructor() {
    this.ormRepository = getRepository(User);
  }

因此,您正在尝试创建一个存储库或管理器,而连接不是established.So,将此语句const repo = await getRepository(User);放入函数中将会起作用!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63830594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档