---
# System prepended metadata

title: 解決 type-orm 在 Serverless invoke RepositoryNotFoundError 解決方案
tags: [nodejs, typescript, serverless]

---

# 解決 type-orm 在 Serverless invoke RepositoryNotFoundError 解決方案
###### tags: `serverless` `nodejs` `typescript`

解決方案：

用 <b>import</b> 的方式，在 createConnection entitie 中 塞入你想要的自動載入的 Entity
```
import { APIGatewayProxyHandler } from 'aws-lambda';
import 'source-map-support/register';
import {createConnection, getConnectionManager, getRepository} from "typeorm";
import {Member as MemberEntity} from "./Entities/Member";
import {Store as StoreEntity} from "./Entities/Store";
import {StoreSetting as StoreSettingEntity } from "./Entities/StoreSetting";
import {Order as StoreOrderEntity} from "./Entities/Order";
import {MemberStar as MemberStarEntity} from "./Entities/MemberStar";



export const hello: APIGatewayProxyHandler = async (event, _context) => {
  _context.callbackWaitsForEmptyEventLoop = false
  console.log("path: " + __dirname );
  await createConnection({
    name: "default",
    type: "mysql",
    host: "127.0.0.1",
    port: 3306,
    username: "root",
    password: "我才不告訴你勒",
    database: "eddie",
    entities: [
      MemberEntity,
      StoreSettingEntity,
      StoreEntity,
      StoreOrderEntity,
      MemberStarEntity
    ]
  })



  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!',
      input: event,
    }, null, 2),
  };
}
```