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

Source maps works locally, but not on AWS Lambda

Open mpmp0 opened this issue 5 years ago • 0 comments

This is a (Bug Report / Feature Proposal)

Description

For bug reports:

  • What went wrong? Error log stack traces not using source map according to CloudWatch Logs. It does show the correct line numbers locally on serverless-offline.
  • What did you expect should have happened? Show the correct line numbers on CloudWatch Logs
  • What was the config you used?

webpack.config.js

const path = require('path')
const slsw = require('serverless-webpack')
const nodeExternals = require('webpack-node-externals')
module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  mode: slsw.lib.webpack.isLocal ? 'development': 'production',
  optimization: {
    minimize: false,
  },
  devtool: 'source-map',
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
    sourceMapFilename: '[file].map'
  }
}

.babelrc

{
  "comments": false,
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "12"
        }
      }
    ]
  ],
  "plugins": [
    "source-map-support"
  ]
}

package.json

  "dependencies": {
    "source-map-support": "^0.5.19",
  },
  "devDependencies": {
    "@babel/core": "^7.10.5",
    "@babel/plugin-transform-runtime": "^7.10.5",
    "@babel/preset-env": "^7.10.4",
    "babel-loader": "^8.1.0",
    "babel-plugin-source-map-support": "^2.1.2",
    "aws-sdk": "^2.704.0",
    "serverless-dotenv-plugin": "^2.4.2",
    "serverless-offline": "^6.3.1",
    "serverless-webpack": "^5.3.2",
    "webpack": "^4.43.0",
    "webpack-node-externals": "^1.7.2"
  }
}

serverless.yml

package:
  individually: false
custom:
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
    keepOutputDirectory: true

plugins:
  - serverless-webpack
  - serverless-offline
  - serverless-dotenv-plugin

top of index.js (handler)

import 'source-map-support/register'
  • What stacktrace or error message from your provider did you see?

Serverless offline local logs:

Error: just throwing
    at Module../index.js (/Users/my-project/services/main/.webpack/service/webpack:/index.js:19:7)
    at __webpack_require__ (/Users/my-project/services/main/.webpack/service/webpack:/webpack/bootstrap:19:1)
    at /Users/my-project/services/main/.webpack/service/webpack:/webpack/bootstrap:83:1
    at Object.<anonymous> (/Users/my-project/services/main/.webpack/service/index.js:88:10)

CloudWatch Logs:

Error
  {
      "errorType": "Error",
      "errorMessage": "just throwing ",
      "stack": [
          "Error: just throwing ",
          "    at Module.<anonymous> (/var/task/index.js:2116:7)",
          "    at __webpack_require__ (/var/task/index.js:21:30)",
          "    at /var/task/index.js:85:18",
          "    at Object.<anonymous> (/var/task/index.js:88:10)",
      ]
  }

For feature proposals:

  • What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
  • If there is additional config how would it look

Similar or dependent issue(s):

  • #228
  • #630

Additional Data

  • Serverless-Webpack Version you're using: 5.3.2
  • Webpack version you're using: 4.43.0
  • Serverless Framework Version you're using: 1.82.0
  • Operating System:
  • Stack Trace (if available):

mpmp0 avatar Sep 09 '20 00:09 mpmp0