question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RepositoryNotFoundError w/ serverless offline

See original GitHub issue

Issue type: [x] bug report

Database system/driver: [x] postgres

TypeORM version: [x] 0.2.7 (or put your version here)

Steps to reproduce or a small repository showing the problem:

  1. Use ormconfig.json, set entities to something like "**/entities/*.{js,.ts}"
  2. Run serverless offline start
  3. Try to get repo like: this.repo = connection.getRepository<User>(User)
  4. I also tried like this.repo = connection.getRepository<User>('User')

Result: RepositoryNotFoundError: No repository for “User” was found. Looks like this entity is not registered in current “dev” connection?

I know my entities are set correctly in my ormconfig.json file b/c my database tables are all synced correctly, but I can’t get a repo to do any work.

Please help!

Here’s my ormconfig.json:

{
    "name": "dev",
    "type": "postgres",
    "host": "localhost",
    "port": 5432,
    "username": "postgres",
    "database": "postgres",
    "entities": [
        "**/entities/*.{js,.ts}"
    ],
    "synchronize": true,
    "logging": false
}

Here’s what my Database class looks like:

export class Database {
    private connectionManager: ConnectionManager

    constructor() {
        Logger.info(`Database()`)
        this.connectionManager = getConnectionManager()
    }

    public async getConnection(): Promise<Connection> {
        Logger.info(`Database.getConnection()`)

        let connection: Connection

        try {
            connection = this.connectionManager.get(process.env.CONNECTION_NAME)
        }
        catch (e) {
            Logger.warn(`Database.getConnection()-error=${e}`)

            // read connection options from ormconfig file (or ENV variables)
            const connectionOptions = await getConnectionOptions(process.env.CONNECTION_NAME);
            Object.assign(connectionOptions, { namingStrategy: new SnakeNamingStrategy() });

            Logger.info(`Database.getConnection()-connectionOptions=${inspect(connectionOptions)}`)

            connection = await createConnection(connectionOptions)
        }

        return connection
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kvarelacommented, Sep 21, 2018

@ganesh9596 I actually had to switch back to explicitly calling out the entities because I switched I had to minify my code (using Browserify) and after minification it no longer makes sense to have a directory structure.

But here’s my current connectionOptions for reference:

export const connectionOptions: ConnectionOptions = {
    name: `default`,
    type: `postgres`,
    synchronize: true, // todo: remove for production, should be replaced with formal migrations once we're launched
    logging: false,
    replication: {
        master: {
            host: process.env.DB_HOST,
            username: process.env.DB_USERNAME,
            database: process.env.DB_NAME,
            password: process.env.DB_PASSWORD,
            port: 5432
        },
        slaves: [
            {
                host: process.env.DB_HOST_SLAVE,
                username: process.env.DB_USERNAME,
                database: process.env.DB_NAME,
                password: process.env.DB_PASSWORD,
                port: 5432
            }
        ]
    },
    namingStrategy: new SnakeNamingStrategy(),
    // This causes problems with minification since there's no longer a directory structure
    // entities: [__dirname + '/entities/*.*']
    entities: [
        Amenity,
        City,
        Hotel,
        HotelAmenity,
        HotelBooking,
        HotelPhoto,
        HotelPolicy,
        HotelRoom,
        HotelSupplyUpdate,
        HotelTag,
        Neighborhood,
        Policy,
        Tag,
        User
    ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

No error on ts-node-dev script, but errors occurred on ...
I'm making serverless project with using node, koa, typescript, ... \typeorm\error\RepositoryNotFoundError.js:11:1) at EntityManager.
Read more >
Serverless offline plugin
Serverless Offline. This Serverless plugin emulates AWS λ and API Gateway on your local machine to speed up your development cycles.
Read more >
serverless-offline/community - Gitter
I'm using serverless-offline 6.5.0 in my project, and want to test my functions which don't have an HTTP events with invocation endpoint (via...
Read more >
Developing locally with Serverless Offline | Reason SLS
Create a Serverless function using slspress. In this tutorial, we are gonna use serverless-offline to create and run Serverless offline.
Read more >
Serverless - FAQ | NestJS - A progressive Node.js framework
With a serverless architecture, you focus purely on the individual functions in your ... aws-lambda $ npm i -D @types/aws-lambda serverless-offline.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found