Lambda 失败 "Cannot find module..."

Lambda fails with "Cannot find module..."

我正在使用 Webpack 打包我的 lambda。我正在使用 CDK 部署它们。

然而,当通过 ApiGateway 测试它们时,我得到了这个:

Lambda execution failed with status 200 due to customer function error: Error: Cannot find module 'apollo-server-lambda'.

这是我的 Webpack 配置:

{
  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: [
  ]
}

node graphql.js一样执行输出文件不会失败。 我做错了什么?

删除

externals: [nodeExternals()]

已解决问题。

它导致依赖项被排除在包之外。