I'm packing my lambdas with Webpack. And I'm deploying them with CDK.
However, when testing them through ApiGateway, I get this:
Lambda execution failed with status 200 due to customer function error: Error: Cannot find module 'apollo-server-lambda'.
Here's my Webpack config:
{
mode: 'production',
entry: {
graphql: './src/lambdas/graphql.ts',
cognito: './src/lambdas/cognito.ts',
'smoke-detector': './src/lambdas/smoke-detector.ts',
},
output: {
libraryTarget: 'commonjs',
path: path.resolve(__dirname, "dist"),
filename: '[name]/[name].js'
},
target: 'node',
externals: [nodeExternals()],
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
loader({
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({
before: [graphqlTag.getTransformer()]
})
}
}
}),
loader({
test: /\.graphqls$/,
use: {
loader: 'graphql-tag/loader',
}
})
]
},
plugins: [
]
}
Executing the output file like node graphql.js doesn't fail.
What am I doing wrong?
Removing
externals: [nodeExternals()]
fixed the problem.
It caused dependencies to be excluded from the bundle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With