Scott
05/03/2022, 1:08 AMError: 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.Yohann B
05/03/2022, 7:10 AMbundle :{
externalModules: ['pg-native']
}
to your lambda function configuration ?Scott
05/03/2022, 7:15 AMthis.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)
'GET /public': {
function: {
handler: 'src/public.main',
},
authorizationType: ApiAuthorizationType.NONE,
bundle: {
externalModules: ['pg-native'],
},
},
Main Application (index.ts)
app.setDefaultFunctionProps({
runtime: 'nodejs14.x',
bundle: {
externalModules: ['pg-native']
}
});
Yohann B
05/03/2022, 7:51 AMFrank
Frank
Frank
Scott
05/04/2022, 12:05 AMScott
05/04/2022, 1:46 AMScott
05/08/2022, 11:42 PMthdxr
05/11/2022, 3:19 AMScott
05/11/2022, 5:57 AM