Is anyone able to help me with setting up a server...
# help
m
Is anyone able to help me with setting up a serverless API using typeorm? I am getting the following error:
Copy code
ERROR Runtime.UnhandledPromiseRejection: TypeError: Cannot read properties of undefined (reading 'filename')
My Typeorm Datasource is as follows:
Copy code
const dataSource = new DataSource({
    type: "aurora-postgres",
    region: "eu-central-1",
    logging: true,
    database: process.env.DB_NAME || "",
    secretArn: process.env.CLUSTER_SECRET_ARN || "",
    resourceArn: process.env.CLUSTER_ARN || "",
    // entities: [TestModel],
  });
and my GraphqlApi is as follows:
Copy code
const api = new sst.GraphQLApi(this, "Api", {
      server: {
        handler: "src/graphql.handler",
        timeout: 3,
      },
      defaults: {
        function: {
          environment: {
            DB_NAME: DATABASE,
            CLUSTER_ARN: cluster.clusterArn,
            CLUSTER_SECRET_ARN: cluster.secretArn,
          },
        },
      },
    });
and my dependencies are also as follows:
Copy code
"devDependencies": {
    "@serverless-stack/cli": "1.0.2",
    "@serverless-stack/resources": "1.0.2",
    "@tsconfig/node14": "^1.0.1",
    "@types/aws-lambda": "^8.10.70",
    "@types/bcrypt": "^5.0.0",
    "@types/data-api-client": "^1.2.4",
    "@types/luxon": "^2.3.2",
    "@types/node": "<15.0.0",
    "aws-cdk-lib": "2.20.0",
    "typescript": "^4.6.4"
  },
  "dependencies": {
    "apollo-server-lambda": "^3.7.0",
    "bcrypt": "^5.0.1",
    "class-validator": "^0.13.2",
    "data-api-client": "^1.3.0",
    "graphql": "^15.3.0",
    "graphql-scalars": "^1.17.0",
    "graphql-upload": "^13.0.0",
    "hcaptcha": "^0.1.1",
    "jsonwebtoken": "^8.5.1",
    "luxon": "^2.3.2",
    "type-graphql": "^1.1.1",
    "typeorm": "^0.3.6",
    "typeorm-aurora-data-api-driver": "^2.4.2"
  }
a
TypeORM uses @decorators on the data models, right? Did you setup an esbuild plugin to process those?
m
Hey thanks for the quick reply, I gave it a quick test by using
@anatine/esbuild-decorators
as follows but am still receiving the same issue. Api Stack:
Copy code
const api = new sst.GraphQLApi(this, "Api", {
      server: {
        handler: "src/graphql.handler",
        timeout: 3,
      },
      defaults: {
        function: {
          bundle: {
            esbuildConfig: {
              plugins: "config/esbuild.js",
            },
          },
          environment: {
            DB_NAME: DATABASE,
            CLUSTER_ARN: cluster.clusterArn,
            CLUSTER_SECRET_ARN: cluster.secretArn,
          },
        },
      },
    });
config/esbuild.js:
Copy code
const { esbuildDecorators } = require("@anatine/esbuild-decorators");

module.exports = [esbuildDecorators()];
a
That's all I have then, short of Googling for you. I don't use TypeORM or GraphQL.
m
Thanks for your help. I've got it working on the serverless framework but it doesn't want to play nicely with serverless-stack for some reason.
f
@Michael Poulgrain are you still having the issue?
Possible to put together a minimal repo with this issue? I will give it a try on my end.