I have a question regarding deployment. `npx sst s...
# help
m
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
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
Hey Ross, thanks for replying. Which file should I add this line to?
r
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
That did the trick. Thanks for the help Ross!
r
excellent!
f
@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
Yeah that's a good idea. Let's make this into an issue.
r
Yeah, a hint as a “you could try this…” would be really helpful
f