To fix this problem, I had to list knex as an external in my webpack config:
// webpack.config.js
module.exports = {
...
externals: { knex: "commonjs knex" }
}
then I had to add custom force include in my serverless config, so it doesn’t try to bundle knex but uses the one installed in the lambda’s environment?
# serverless.yml
custom:
webpack:
includeModules:
forceInclude:
- knex
- pg # I'm using postgres