Sourcemaps for Node app behind PM2 not working

Hi everyone,

I think I have read all sourcemaps related posts on this forum, searched Google and spent around 20 hours trying to figure this out on my own, but to no avail. I’m out of my league :frowning:

I have an isomorphic app (based on Razzle). In that app, I have hooked up a view (with react-router and loadable-components) that I expect to crash:

import React from 'react'

const TestSentrySSRErrorView = () => {
  myUndefinedFunction()
  return <div />
}

export default TestSentrySSRErrorView

When I run my build process, it generates one big server.js file and one server.js.map file.

At the bottom of server.js I can see this: //# sourceMappingURL=server.js.map

The sources key in my map file has a lot of things that look like this: "webpack:///./src/pages/TestSentrySSRErrorView.js"

I can see that the actual source code is also embedded in the sourcemap.

This is how I uploaded the artifacts to Sentry:

sentry-cli releases -p $PROJECT files $RELEASE  upload-sourcemaps --validate --rewrite ./build_sentry/client/

I can see the artifacts in Sentry and when I download the sourcemap, a vimdiff between the two files shows me that Sentry has changed around the order of the keys but it seems like all the values are still the same (not 100% sure about it, but I can still see "webpack:///./src/pages/TestSentrySSRErrorView.js", for example).

When I now deploy this code and browse to the buggy view and I run pm2 log on the server, I can see the following traceback:

0|server  | ReferenceError: myUndefinedFunction is not defined
0|server  |     at t.default (/home/deploy/razzle/server.js:1:806782)`

When the issue arrives in Sentry, I can see several things wrong with it:

There is a red warning box complaining about not-found code:

  • app:///react-ssr.cjs.js
  • app:///react-dom-server.node.development.js

And one warning about “invalid location in sourcemap” (I assume this is the main issue):

  • app:///server.js.map

The traceback looks like this:

ReferenceError: myUndefinedFunction is not defined
  Module "server", line 10, col 10, in t.default
    
  File "app:///react-dom-server.node.development.js", line 3090, col 14, in processChild
    inst = Component(element.props, publicContext, updater);

As you can see, not very useful…

All this used to work OK with sentry-raven (it showed the correct filename and line number, but didn’t show the sourcecode because I never used Releases and Artifacts before), now I have put so much time into upgrading to @sentry/browser, I can’t go back. Any help will be greatly appreciated!

EDIT: I found sourcemaps.io (apparantly run by Sentry), uploaded my two files to S3 and put the link into that tool, result: It’s green, no warnings, so the sourcemaps that my webpack config generates are OK, I guess?

EDIT: Oh my god, when I kill pm2 on the server and simply run my app via node server.js, it works perfectly. Now I need to figure out how to make PM2 behave…

EDIT: I give up. When I put the app behind supervisor, the tracebacks come in nicely, but I can’t really do that, because I needs PM2’s max-memory-limit and graceful restart feature, no other process manager does it as nicely as PM2. I have tried everything with PM2 now, cluster mode, fork-mode, no luck.