Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting sourcemaps to work #108

Closed
ajmath opened this issue Feb 27, 2017 · 12 comments
Closed

Getting sourcemaps to work #108

ajmath opened this issue Feb 27, 2017 · 12 comments

Comments

@ajmath
Copy link

ajmath commented Feb 27, 2017

What is the trick for getting sourcemaps to work correctly with the stacktraces in AWS logs?

I've currently got require('source-map-support').install(); after all other imports in a file /src/lambdas/webhook.ts.

Webpack config looks like this:

var path = require('path');

module.exports = {
  entry: {
    '/src/lambdas/webhook': './src/lambdas/webhook.ts',
    '/src/lambdas/queue-poller': './src/lambdas/queue-poller.ts',
    '/src/lambdas/queue-worker': './src/lambdas/queue-worker.ts',
  },
  target: 'node',
  devtool: 'source-map',
  resolve: {
    modules: [
      path.join(__dirname, 'src'),
      path.join(__dirname, 'node_modules')
    ],
    extensions: ['', '.ts', '.js']
  },
  module: {
    loaders: [
      { test: /\.ts(x?)$/, loader: 'ts-loader' }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
};

Here is the contents of the uploaded zip:

 ⇒ unzip -l .serverless/trebuchet.zip
Archive:  .serverless/trebuchet.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     3020  02-24-2017 22:37   src/lambdas/queue-poller.js
     3140  02-24-2017 22:37   src/lambdas/queue-poller.js.map
     2956  02-24-2017 22:37   src/lambdas/queue-worker.js
     3073  02-24-2017 22:37   src/lambdas/queue-worker.js.map
  3655773  02-24-2017 22:37   src/lambdas/webhook.js
  5682470  02-24-2017 22:37   src/lambdas/webhook.js.map
---------                     -------
  9350432                     6 files

The output for both logged exceptions and unhandled exceptions is still using the full bundle.

Am I missing something from the source-map-support config?

If everything is working correctly should the logged and unhandled exceptions be using the stacktraces from the sourcemap?

@benjaminwood
Copy link
Contributor

Has anybody figured out how to get source-map-support to work? In my case I'd like source-maps to be used in the trace when I invoke a function locally. As shown in the readme: serverless webpack invoke --function <function-name>

@ajmath
Copy link
Author

ajmath commented Jul 12, 2017

In my case, I believe the issue was with my tsconfig file. I can't speak to other languages/frameworks though. Since then, we've moved to using serverless-typescript-plugin since we're not building a UI and don't have as much to gain for the added complexity of webpack.

@benjaminwood
Copy link
Contributor

Okay, thanks for following up!

@HyperBrain Perhaps #151 would have some impact on getting source-map-support to work when invoking a function locally?

@HyperBrain
Copy link
Member

@benjaminwood I think so. We should check for the source-map support as soon as the native Serverless invoke is used. Then any problems can be finally solved.
I'll take care of #151 soon so that we can proceed.

@benjaminwood
Copy link
Contributor

Thanks @HyperBrain, that'd be awesome!

@HyperBrain
Copy link
Member

@benjaminwood A V3 RC is released now on npm serverless-webpack@3.0.0-rc.1. Would be cool if you can try to get the sourcemap support running with serverless invoke local 😃

@benjaminwood
Copy link
Contributor

Hey @HyperBrain I ran into an error before my handler would be called. To ensure it is related to the new version of serverless-webpack, I confirmed that if I roll-back to an older version things work as expected (by using serverless webpack invoke)

Here's a backtrace:
https://gist.github.com/benjaminwood/65a9f3a346f9c5cf24e9a28b48778ee1

Perhaps this should have its own/new issue. I'm happy to create one, let me know. Thanks for working on this! You've been making lots of progress on this package which is real exciting.

@HyperBrain
Copy link
Member

HyperBrain commented Aug 10, 2017

It looks like a configuration problem. Could you post the function definition in serverless.yml of the export function and the webpack config? If you've not done that already, you should switch to automatic entry resolution with slsw.lib.entries though (already available in v2.2.0).

@HyperBrain
Copy link
Member

HyperBrain commented Aug 10, 2017

Just went through the callstack again. It's definitely a configuration issue - your entry is "main" but your handler is "handler". This makes it impossible for the plugin and, more important, Serverless to find the handler. Please change your "entry" definition to be entry: slsw.lib.entries and your output filename to [name].js. This makes sure that the entries are reverse resolvable to the handlers (which are started by sls invoke local).

@benjaminwood
Copy link
Contributor

In my webpack config it was defined as: entry: './handler.js',

However, changing it to entry: slsw.lib.entries as you suggested resolved this. Thank you for your help, and I apologize for being a noob. 😄

🎉🎉🎉And with that.... source-map-support works! 🎉🎉🎉

Thanks again!

@HyperBrain
Copy link
Member

@benjaminwood Great to hear that this solved your problem 👍 . You're not a "noob" - the feature is quite new, so many people just don't know that it exists 😄

@HyperBrain
Copy link
Member

This issue is solved with v3. Will be closed as soon as #175 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants