serverless-webpack icon indicating copy to clipboard operation
serverless-webpack copied to clipboard

WebPack production causes error but development does not. Production optimization override?

Open Borduhh opened this issue 3 years ago • 3 comments

This is a (Bug Report / Feature Proposal)

Description

For bug reports:

  • What went wrong? WebPack Production mode causing TypeError at runtime with node_module import
  • What did you expect should have happened? The code should compile and run as expected
  • What was the config you used?
const path = require('path');
const slsw = require('serverless-webpack');

module.exports = {
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  externals: ['aws-sdk', 'saslprep'],
  entry: slsw.lib.entries,
  devtool: slsw.lib.webpack.isLocal ? 'cheap-module-eval-source-map' : 'source-map',
  resolve: {
    extensions: ['.mjs', '.json', '.ts', '.js'],
    symlinks: false,
    cacheWithContext: false,
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
  },
  target: 'node',
  optimization: {
    nodeEnv: false,
  },
  module: {
    rules: [
      {
        test: /\.(tsx?)$/,
        loader: 'ts-loader',
        exclude: [
          [
            path.resolve(__dirname, 'node_modules'),
            path.resolve(__dirname, '.serverless'),
            path.resolve(__dirname, '.webpack'),
          ],
        ],
        options: {
          transpileOnly: true,
          experimentalWatchApi: true,
        },
      },
    ],
  },
};

  • What stack trace or error message from your provider did you see?
{
    "timestamp": "2021-04-15T13:29:18.821Z",
    "level": "ERROR",
    "name": "TypeError",
    "message": "t.plugpulseInternalSdk.transaction.createTransaction is not a function",
    "stack": "TypeError: t.plugpulseInternalSdk.transaction.createTransaction is not a function\n    at Runtime.t.handler (/var/task/src/functions/startTransaction.js:2:786838)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)",
    "type": "Internal Error",
    "service": "evses-service"
}

Additional Data

  • Serverless-Webpack Version you're using: 5.4.1
  • Webpack version you're using: 5.33.2
  • Serverless Framework Version you're using: 2.35.0
  • Operating System: AWS Lambda - NodeJS 14.x.x

Borduhh avatar Apr 15 '21 13:04 Borduhh

Code causing the issue:

Serverless Handler Function (replaced package name with "InternalSdk" for privacy)

export const handler = async (
  event: AWSLambda.APIGatewayProxyEvent
): Promise<AWSLambda.APIGatewayProxyResult> => {
/* . . . */
    const driverResponse = await InternalSdk.driver.authorize({ idTag });

    const transactionResponse = await InternalSdk.transaction.createTransaction(
      transactionRequest
    );
/* . . . */
}

Borduhh avatar Apr 15 '21 14:04 Borduhh

same bug for me..

UserLambdaValidationException: PostConfirmation failed with error i.putItem is not a function.

orr-levinger avatar Apr 17 '21 09:04 orr-levinger

same bug for me..

UserLambdaValidationException: PostConfirmation failed with error i.putItem is not a function.

We are just running everything in Development mode for now.

Borduhh avatar Apr 24 '21 13:04 Borduhh