question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

source-map support in production and locally

See original GitHub issue

Version: “serverless-webpack”: “3.0.0”

I am wondering if anyone has gotten source-map support working on production system. Because debugging based on AWS CloudWatch input has always been a good way to find problems in the production system. Identifying the problem with output like at products (C:/Users/piust/Documents/colugo/.webpack/service/handler.js:4173:61) is really hard.

Has anyone gotten a solution for this? I’m running basic configuration from what I understand from webpack:

const path = require('path')
const Dotenv = require('dotenv-webpack')
const slsw = require('serverless-webpack')

module.exports = {
  devtool: 'source-map',
  entry: slsw.lib.entries,
  target: 'node',
  module: {
    rules: [{
      test: /\.js$/,
      loader: 'babel-loader',
      include: __dirname,
      exclude: /node_modules/,
      options: {
        presets: ['es2015', 'stage-2'],
        plugins: ['transform-runtime'],
      },
    }],
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.resolve(__dirname, '.webpack'),
    filename: 'handler.js', // this should match the first part of function handler in `serverless.yml`
  },
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

20reactions
araboldcommented, Sep 18, 2017

Make sure to add require('source-map-support').install(); or import "source-map-support/register"; to the top of your Lambda handlers to load the source map. Otherwise it will not be used. See here: https://github.com/evanw/node-source-map-support

4reactions
nenticommented, Jul 3, 2018

I found a reasonable setup. Cloud logs work great. Local debugging is okayish.

Dependencies:

"babel-core": "6.25.0",
    "babel-loader": "^7.1.4",
    "babel-plugin-source-map-support": "^2.0.1",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-2": "^6.24.1",
    "babel-jest": "^23.0.1",
    "regenerator-runtime": "^0.10.5",
    "serverless": "^1.27.1",
    "serverless-jest-plugin": "^0.1.6",
    "serverless-offline": "^3.23.0",
    "serverless-webpack": "^5.1.5",
    "webpack": "^4.8.3",
    "jest": "^23.1.0",
    "jest-junit": "^5.0.0",
    "jest-sourcemaps": "^1.0.1",
    "webpack-node-externals": "^1.7.2"

Wepack config:

const webpack = require('webpack')
const path = require("path")
const nodeExternals = require('webpack-node-externals')
const slsw = require('serverless-webpack')

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

.babelrc

{
  "comments": false,
  "sourceMaps": "both",
  "presets": [
    ["env", {
      "targets": {
        "node": "6.10"
      }
    }],
    "stage-2"
  ],
  "plugins": [
    "source-map-support"
  ]
}

Hope it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable source-map on production? - Medium
Step 1: Following code generates source map files for us. ... Step 2: Create URL morphing service which will take URL as an...
Read more >
Should I Use Source Maps in Production? | CSS-Tricks
A "source map" is a special file that connects a minified/uglified version ... It might help you track down bugs in production more...
Read more >
Using sourcemaps on production without exposing the source ...
Main takeaway is that you can specify the url to load sourcemaps from, and this allows you to debug minified application on production,...
Read more >
How to use source maps in AWS Lambda with Node.js
A Lambda function without source map support. Let's start with a simple Lambda function without source maps. To add this function, open the...
Read more >
Apply sourcemaps on local file system to minified production ...
Are you after troubleshooting a production issue (resolving a minified stack trace) or you just want to run prod code locally with source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found