also it appears `source-map-support` isn’t working...
# sst
t
also it appears
source-map-support
isn’t working either. I’m wondering if that’s because it separates the sourcemap from the code during build, instead of inlining it?
t
I do believe we upload the sourcemap along with the bundled output
t
yeah that’s definitely happening, but for some reason source-map-support isn’t able to grab it or backtrack the original source
as an example, here’s a lambda handler file:
Copy code
import Koa                  from 'koa';
import bodyParser           from 'koa-bodyparser';
import serverless           from 'serverless-http';
import { isDev }            from 'serverless-boost/app';
import { processRequest }   from 'serverless-boost/lambda/request';
import { createContext }    from '../app';
import endpoints            from '../web';

// init the global context
const context = createContext();

// init the app
const web = new Koa();

// plumb the web stack
web
  .use(bodyParser());

// log the requests
web.use(function(ctx, next) {
  console.log(`${ctx.method} ${ctx.path}`);
  return next();
});

// inject the global context into the request ctx state
web.use(function(ctx, next) {
  ctx.state = context;
  return next();
});

// attach endpoints
for (let { handle: attach } of endpoints) {
  attach(web);
}

// run the serverless stack directly
export const main = processRequest(serverless(web));
but mostly at the top, you can see
sourceMap.install()
then I created a simple handler to bonk so I could see the backtrace in the output logs
t
Ah not familiar with what source-map-support is, need to look into it
it basically fixes stacktraces?
t
oh wait…
I might not have it configured…
yep, it wasn’t configured. I was looking at the wrong project. Now I’m trying…
source-map-support
basically fixes the default error stack backtrace to walk back through the source maps and get to the original source. So when you’re seeing the stack trace it’s the actual source, whether typescript, javascript, coffeescript, etc before it was compiled and minified.
ok that works when it’s actually configured haha
t
that's good!
and cool, I might start using that as well
t
basically you just import it at the top of the lambda handler file, and then the very first thing you do is install it:
Copy code
import sourceMap from 'source-map-support'

// source map support for sanity
sourceMap.install();

// handle the request
export const main = ...
so now my error message looks like this:
Copy code
ReferenceError: bonk is not defined
      at /src/web/status.js:14:5
instead of this:
Copy code
ReferenceError: bonk is not defined
      at /var/task/src/lambda/web.js:28593:5
which is the correct location in the original source 💪