Typeorm + Firebase functions: "No connection options were found in any orm configuration files" after deployed

Viewed 327

Env:nodejs12

Folder structure:

#root
/functions
  /src
    ...
    /models
    /resolvers
    index.ts
  ormconfig.json
  package.json
  tsconfig.json
  ...
.firebaserc
firebase.json

Everything worked when developing in local environment. After deployed to firebase functions, No connection options were found in any orm configuration files shows up.

What might be the cause?

I'll update with more information if needed.

=========================================

update

Below is the folder structure of deployed codes. (Cloud functions can't show more than 50 files so I downloaded the source code from GCP)

folder structure

cloud functions SOURCE tab

As you can see the ormconfig.json does exist in the root, but somehow it cannot be located. I have to create connection manually with typeorm.createConnection({type: "postgres",...}) to make the code work.

1 Answers

This is likely being caused by a known bug with app-root-path (which TypeORM uses for config file resolution) when used in conjunction with Google Cloud Functions.

The workaround / fix that worked for me was to set the environment variable APP_ROOT_PATH to /workspace when I deployed my Google Cloud Function (app-root-path will short-circuit when it sees that variable).

Related