sentry-javascript: Followed source map instructions, but line numbers are wrong, etc
- Review the documentation: https://docs.sentry.io/
- Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
- Use the latest release: https://github.com/getsentry/sentry-javascript/releases
- Provide a link to the affected event from your Sentry account
Package + Version
-
@sentry/node- 5.18.1 -
@sentry/integrations- 5.18.1 -
@sentry/webpack-plugin- 1.11.1
Description
I’ve followed the instructions on source maps to the best of my knowledge. I’m trying this out with a Serverless Framework setup.
It’s quite an improvement over how reporting looked before I followed the steps, but the line number is totally wrong and the module name is missing. There’s also still remnants of webpack variable names.
https://sentry.io/organizations/reelcrafter/issues/1749922899/?project=5298557
webpack.config.js
const path = require("path");
// eslint-disable-next-line import/no-unresolved
const slsw = require("serverless-webpack");
const SentryPlugin = require("@sentry/webpack-plugin");
module.exports = {
entry: slsw.lib.entries,
devtool: "source-map",
output: {
libraryTarget: "commonjs",
filename: "[name].js",
path: path.join(__dirname, ".webpack"),
},
mode: "development",
target: "node",
module: {
rules: [
{
test: /\.js$/, // include .js files
enforce: "pre", // preload the jshint loader
exclude: /node_modules/, // exclude any and all files in the node_modules folder
include: __dirname,
use: [
{
loader: "babel-loader",
},
],
},
],
},
plugins: [
new SentryPlugin({
release: process.env.RELEASE,
include: "./.webpack",
}),
],
};
test.js
import * as Sentry from "@sentry/node";
import { RewriteFrames } from "@sentry/integrations";
Sentry.init({
dsn: "https://xx",
release: process.env.RELEASE,
integrations: [new RewriteFrames()],
});
/**
...
*/
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (9 by maintainers)
😶
I found the main issue. It’s TerserPlugin messing around with the source code.
Add this to your webpack config and you should be good no matter what
modeis set! (this is the only change I did base on your current repo state).You can play around with
TerserPlugindefault options to find which exactly is the culprit if you want to use it nonetheless - https://webpack.js.org/plugins/terser-webpack-plugin/#terseroptionsAnytime, I’m curious myself what’s going in here 😄
For anyone who might still have problems with the source map line numbers while using Terser plugin, I could get it working properly by disabling the following compress options in
terserOptions:Ahh, I just figured out why this solution was working fine on my test project, but not an actual real project!
In my real project, all my code is under
src/. So I had to change theincludein thewebpack.config.js:When it was just
include: "./.webpack/service",, the source maps were way off.@ffxsam I was struggling with this issue as well for a while. A few weeks ago I wrote an article on how to make it work. Maybe it helps you: Fix sentry sourcemaps in AWS lambda functions
TLDR:
@ffxsam you forgot to import
basenamemethod from builtinpathpackage 😅 I’ll take a look at the rest of the code tomorrow and get back to you.