https://serverless-stack.com/ logo
#help
Title
# help
m

Michael James Munar

03/02/2022, 10:48 AM
I have a question regarding deployment.
npx sst start
^ when I run this, everything works fine, but on deployment I keep getting this error which I couldn't find how to fix
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')
      ╵                      ~~~~~~~~~~~
    at Object.bundle (/tmp/seed/source/node_modules/@serverless-stack/core/dist/runtime/handler/node.js:226:23)
    at Object.bundle (/tmp/seed/source/node_modules/@serverless-stack/core/dist/runtime/handler/handler.js:19:16)
    at new Function (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Function.ts:362:39)
    at Function.fromDefinition (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Function.ts:514:14)
    at Api.createFunctionIntegration (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Api.ts:579:23)
    at Api.addRoute (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Api.ts:466:26)
    at /tmp/seed/source/node_modules/@serverless-stack/resources/src/Api.ts:303:12
    at Array.forEach (<anonymous>)
    at Api.addRoutes (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Api.ts:302:25)
    at new Api (/tmp/seed/source/node_modules/@serverless-stack/resources/src/Api.ts:272:10)
There was an error synthesizing your app.
Anybody knowledgeable on bundling, please enlighten me Edit: the package I added is
pg-promise
-> https://github.com/vitaly-t/pg-promise
r

Ross Coundon

03/02/2022, 10:50 AM
I think you probably need to set:
Copy code
bundle.nodeModules = ['pg-promise']
to force the install of this rather than having it bundled
m

Michael James Munar

03/02/2022, 11:03 AM
Hey Ross, thanks for replying. Which file should I add this line to?
r

Ross Coundon

03/02/2022, 11:13 AM
Copy code
export default function main(app: <http://sst.App|sst.App>): void {
  app.setDefaultFunctionProps({
    bundle: {      
      nodeModules: ['pg-promise'],
    },

  });

  new YourStack(app, 'your-stack');
}
We do it like that in the index.ts
m

Michael James Munar

03/02/2022, 11:30 AM
That did the trick. Thanks for the help Ross!
r

Ross Coundon

03/02/2022, 11:38 AM
excellent!
f

Frank

03/03/2022, 6:15 AM
@Jay @thdxr This has been a recurring issue, and @Ross Coundon has helped quite a few ppl with this 😂 Should we track a list of these un-bundle-able modules, grep for the error message
Could not resolve "xxxx"
, and then suggest a fix? Better ideas?
j

Jay

03/03/2022, 12:12 PM
Yeah that's a good idea. Let's make this into an issue.
r

Ross Coundon

03/03/2022, 12:18 PM
Yeah, a hint as a “you could try this…” would be really helpful
f

Frank

03/03/2022, 12:47 PM
2 Views