Has anyone had recent luck with getting typeORM im...
# help
s
Has anyone had recent luck with getting typeORM implemented with SST? I've tried previously mentioned solutions for externalModules/nodeModules for pg-native but cannot seem to by-pass the error when running sst build/seed deploy:
Copy code
Error: There was a problem transpiling the Lambda handler: > node_modules/pg/lib/native/client.js:4:21: error: Could not resolve "pg-native" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    4 │ var Native = require('pg-native')
Note - The above works locally with sst start I've also tried an alternative solution which involves having a mocked pg-native library (which just returns an empty module). This actually works with sst build & seed deploy, BUT then sst start runs into issues running typeORM locally. See attached error. I'm currently at a stand still of either typeORM works locally OR online, but have been unable to find a solution that works for both.
y
Are you sure you added :
bundle :{
Copy code
externalModules: ['pg-native']
}
to your lambda function configuration ?
s
@Yohann B, thanks for the reply, I've tried that in multiple places, but out of interest. What would be the most correct location for it? Api stack level (ApiStack.ts)
Copy code
this.api = new Api(this, 'Api', {
defaultAuthorizationType: ApiAuthorizationType.AWS_IAM,
defaultFunctionProps: {
    environment: {
        // PRODUCTS_BUCKET: productsBucket.bucketName,
        // LISTINGS_BUCKET: listingsBucket.bucketName,
        DATABASE: DATABASE,
        CLUSTER_ARN: database.clusterArn,
        SECRET_ARN: database.secretArn,
        REGION: scope.region,
    },
    permissions: [database],
    bundle: {
        externalModules: ['pg-native'],
    },
},
Function Level (ApiStack.ts)
Copy code
'GET /public': {
    function: {
        handler: 'src/public.main',
    },
    authorizationType: ApiAuthorizationType.NONE,
    bundle: {
        externalModules: ['pg-native'],
    },
},
Main Application (index.ts)
Copy code
app.setDefaultFunctionProps({
    runtime: 'nodejs14.x',
    bundle: {
        externalModules: ['pg-native']
    }
});
y
Something seems off with your config, maybe you can install pg-native locally so it will be included for now and won't create the problem
f
Thanks for chiming in @Yohann B!
@Scott can you put together a sample repo (ie. 1 function) that reproduces this error?
And I will give it a try on my end.
s
Will see if I can put that together today, cheers @Frank
@Frank I created a new repo here - https://github.com/Scott-lasertrade/typeorm-poc It builds+runs fine with sst build/seed, but replicates the error I get above or rather there is no error unless you turn on uncaught exceptions with breakpoints. So generally it just hangs, let me know how you go.
@Frank, did you have any luck/trouble with the repo above or does it work on your end?
t
I'll be looking into this tomorrow @Scott
s
Cheers @thdxr, had to make a bit of a judgement call, have started on conversion to kysely so may not be as relevant now - pending whether I can get it all working as it's quite a big migration.