sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Serverless Typescript source maps not working.

Open mmazurowski opened this issue 3 years ago • 2 comments

Environment

SaaS (https://sentry.io/)

Version

No response

Steps to Reproduce

Hello there 👋

I am having issues with getting source maps to work. I am experiencing issues with "Invalid location in sourcemap (see Troubleshooting for JavaScript)"

So far I have double checked:

  1. Artifacts have been uploaded to the sentry with release tag matching error release.
  2. Source maps works locally as per troubleshooting guide

Screenshot 2022-09-15 at 11 27 42

How can I debug it further?

Kind regards, Marcin

Expected Result

Source maps are working for typescript based lambda

Actual Result

Webpack config:

const path = require("path");
const slsw = require("serverless-webpack");
const CopyPlugin = require("copy-webpack-plugin");
const SentryPlugin = require("@sentry/webpack-plugin");
const webpack = require("webpack");

module.exports = {
  plugins: [
    new webpack.SourceMapDevToolPlugin({
      noSources: false,
      filename: "[name].js.map",
    }),
    new SentryPlugin({
      release: process.env.SERVICE_VERSION,
      org: process.env.SENTRY_ORGANIZATION,
      project: process.env.SENTRY_PROJECT,
      authToken: process.env.SENTRY_AUTH_TOKEN,
      include: ".webpack",
      ignore: ["node_modules", "webpack.config.js"],
      setCommits: {
        auto: true,
      },
      deploy: {
        env: process.env.SENTRY_ENV || "ENV_NAME_NOT_PROVIDED",
      },
      validate: true,
      sourceMapReference: true,
    }),
  ],
  entry: slsw.lib.entries,
  mode: "none",
  target: "node14",
  externals: ["aws-sdk"],
  node: {
    __dirname: true,
  },
  resolve: {
    extensions: [".js", ".json", ".ts", ".tsx"],
  },
  optimization: {
    minimize: false,
  },
  output: {
    libraryTarget: "commonjs",
    path: path.join(__dirname, ".webpack"),
    filename: "[name].js",
  },
  ignoreWarnings: [
    {
      module: /node_modules\/typeorm/,
      message: /Can't resolve/,
    },
    {
      module: /node_modules/,
      message: /Critical dependency: the request of a dependency is an expression/,
    },
  ],
  module: {
    rules: [
      {
        test: /\.ts(x?)$/,
        exclude: [/plop-templates/, /node_modules/],
        use: [
          {
            loader: "ts-loader",
            options: {
              transpileOnly: process.env.NODE_ENV !== "dev",
            },
          },
        ],
      },
      {
        test: /\.js$/,
        exclude: [/node_modules/, /plop-templates/],
        use: [
          {
            loader: "babel-loader",
          },
        ],
      },
    ],
  },
};

Example sentry frame:

{
"function": "<anonymous>",
"module": "functions.test-sentry-tag-lambda:handler",
"filename": "/var/task/test-sentry-tag-lambda/handler.js.map",
"abs_path": "/var/task/test-sentry-tag-lambda/handler.js.map",
"lineno": 38803,
"colno": 18,
"context_line": "",
"in_app": true
},

mmazurowski avatar Sep 15 '22 09:09 mmazurowski

Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️

getsentry-release avatar Sep 16 '22 16:09 getsentry-release

Hi, thanks for writing in! Can you post a link to a Sentry Error where sourcemaps aren't working?

lforst avatar Sep 19 '22 09:09 lforst

Hi @lforst

I was able to solve the issue. Problem was that webpack generated source maps point to .js files not ts and sentry could not detect them in repo.

Kind regards, M

mmazurowski avatar Sep 27 '22 12:09 mmazurowski