question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

with-sentry-simple source maps not showing on sentry

See original GitHub issue

Bug report

Following the with-sentry-simple example I couldn’t get the source-maps/source code errors to report correctly to sentry (without Enable JavaScript Source Fetching enabled)

The output doesn’t include the source maps or non-minified source code (as shown in the following screenshot) image

Error: Sentry Integration Test
  at Q(/_next/static/n0pMAb7sGd6y3KHnKw893/pages/demo.js:1:13269)
  at Object.o(/_next/static/chunks/framework.98c1b221acb34aa9927b.js:1:11780)
  at p(/_next/static/chunks/framework.98c1b221acb34aa9927b.js:1:11923)

I have to enable the feature to get the sentry error as shown below in expected behavior) I’ve tried uploading the source may using multiple different approaches but didn’t manage to get anything workable

The example mentions this in the README, but doesn’t include any example of how to make this work…

To Reproduce

Clone the repo apply the following changes to next.config.js

const { parsed: localEnv } = require("dotenv").config();
const webpack = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");

// Package.json => "@zeit/next-source-maps": "^0.0.4-canary.1",
const withSourceMaps = require("@zeit/next-source-maps")({ devtool: "source-map" });

module.exports = withSourceMaps({
  target: "serverless",
  env: {
    // Will be available on both server and client
    // Sentry DNS configurations
    SENTRY_DNS: process.env.SENTRY_DNS,
  },
  poweredByHeader: false,

  webpack(config, options) {
    config.plugins.push(new webpack.EnvironmentPlugin(localEnv));
    config.resolve.plugins.push(new TsconfigPathsPlugin());
    config.node = {
      // Fixes node packages that depend on `fs` module
      fs: "empty",
    };

    if (!options.isServer) {
      config.resolve.alias["@sentry/node"] = "@sentry/browser";
    }

    return config;
  },
});

add tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "paths": {
      "@src/*": ["./src/*"],
      "@components/*": ["./src/components/*"],
      "@services/*": ["./src/services/*"],
      "@utils/*": ["./src/utils/*"]
    },
    "removeComments": false,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "sourceRoot": "/",
    "strict": true,
    "target": "es6",
    "jsx": "preserve"
  },
  "exclude": [
    "node_modules",
    "cypress",
    "test",
    "public",
    "out"
  ],
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "compileOnSave": false
}

The script used to upload the source-maps during build time

configure-sentry-release.sh
#!/bin/bash
set -eo pipefail

# Install Sentry-CLI
curl -sL https://sentry.io/get-cli/ | bash

export SENTRY_ENVIRONMENT="production"
export SENTRY_RELEASE=$(sentry-cli releases propose-version)

# Configure the release and upload source maps
echo "=> Configure Release: $SENTRY_RELEASE :: $SENTRY_ENVIRONMENT"
sentry-cli releases new $SENTRY_RELEASE --project $SENTRY_PROJECT
sentry-cli releases set-commits --auto $SENTRY_RELEASE
sentry-cli releases files $SENTRY_RELEASE upload-sourcemaps ".next" --url-prefix "~/_next" 
sentry-cli releases deploys $SENTRY_RELEASE new -e $SENTRY_ENVIRONMENT
sentry-cli releases finalize $SENTRY_RELEASE

Configure Sentry project (with the Enable JavaScript Source Fetching disabled) image

adding an example demo page that trigger an error

import * as React from "react";

function myErrorFunction() {
  console.log("Error");
  throw new Error("Sentry Integration Test");
}

const Demo = () => {
  return (
    <>
      <h1 onClick={myErrorFunction}>Hello Sentry/Next.js 👋</h1>
    </>
  );
};

export default Demo;

Expected behavior

Having an error report similar to

Error: Sentry Integration Test
  at myErrorFunction(./src/pages/demo.tsx:23:9)
  at apply(./node_modules/react-dom/cjs/react-dom.production.min.js:14:82)
  at ja(./node_modules/react-dom/cjs/react-dom.production.min.js:14:235)
  at ka(./node_modules/react-dom/cjs/react-dom.production.min.js:14:289)

image

System information

  • OS: MacOS 10.14
  • Node version: 12.6.X
  • Version of Next.js: 9.3.4

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
amorriscodecommented, Apr 16, 2020

Got it working, was using the incorrect variable in the webpack plugin. I guess I shouldn’t code at 5 am. 🤦

0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Source Maps for JavaScript
In case the source map files do not contain your original source code ... go to the Source Maps page in project settings,...
Read more >
Sentry's sourcemaps/artifacts don't work - Stack Overflow
Artifacts are sent to sentry.io with webpack-sentry-plugin. The javascript code is run from localhost:8080/js/app.js . It contains //# sourceMappingURL=app.js.
Read more >
前端监控进阶篇— Sentry 监控Next.js 项目实践 - 掘金
第一个with-sentry-simple是一个最基础的简单示例,但是此Demo 存在bug —— 只 ... yarn add @zeit/next-source-maps @sentry/webpack-plugin 复制代码.
Read more >
warning: kite has been deprecated because it is not ... - You.com
We'll show this source more for all searches ... See https://github.com/lydell/source-map-resolve#deprecated warning ... with-sentry-simple
Read more >
Sentry Doesn'T Use The Sourcemap Of Vuejs Project - ADocLib
Vue Error Monitoring With Complete Stack Traces See the error and Vue stack trace previously only visible in your user's debug console. Apply ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found