Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Next.js example #83

Merged
merged 6 commits into from
Mar 20, 2020
Merged

Added Next.js example #83

merged 6 commits into from
Mar 20, 2020

Conversation

jamesmosier
Copy link
Contributor

@jamesmosier jamesmosier commented Mar 7, 2020

This example shows how to use rollbar-sourcemap-webpack-plugin with Next.js

I am using the nosources-source-map webpack devtool in this example which is described in the webpack docs as:

nosources-source-map - A SourceMap is created without the sourcesContent in it. It can be used to map stack traces on the client without exposing all of the source code. You can deploy the Source Map file to the webserver.


Pertinent files in this PR:

  • examples/next-js/next.config.js
  • examples/next-js/pages/_document.js
  • examples/next-js/README.md

Previously I tried using hidden-source-map but Rollbar reported that the sourcemap was found but because Next doesn't add min.js extensions to the actual source files, Rollbar said it assumed the files were not minified and therefore wouldn't associate the uploaded map files with the source files on the server. Therefore nosources-source-map will allow the map files to be uploaded to Rollbar and also includes a comment at the end of each file with the destination of the sourcemap (which does not contain actual source code).


Closes #67

@jamesmosier jamesmosier mentioned this pull request Mar 7, 2020
@pjaws
Copy link

pjaws commented Mar 8, 2020

I know you've probably spent a lot of time on this, but if you're able to, I would really recommend switching to Sentry. Took me 5 minutes to set up and never had a problem. I've had dozens with Rollbar, which I'm stuck with because that's what my company uses.

Thanks for this PR, though! I'll take a look and give it a shot. Hopefully it solves my source map woes at least! 😁

<html lang="en">
<Head>
<script
dangerouslySetInnerHTML={{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it looks like this will only log client-side errors, right? I've set up my project for both client and server, though the source maps have continued to be an issue for me. I can post my config once I (hopefully) get this all working in my project!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I figured for a minimal example that will help other get started in the right direction I would just use the browser SDK. Otherwise setting up Rollbar via their npm package starts to really get into the weeds with implementation details of Rollbar. Ultimately for those using the npm SDK it'd be a similar setup from a Rollbar initialization perspective:

import RollbarSdk from 'rollbar';

new RollbarSdk({
  enabled: ${process.env.NODE_ENV === 'production'},
  accessToken: `${process.env.ROLLBAR_ACCESS_TOKEN}`,
  captureUncaught: true,
  captureUnhandledRejections: true,
  payload: {
    environment: `${process.env.NODE_ENV || 'production'}`,
    client: {
      javascript: {
        source_map_enabled: true,
        code_version: `${process.env.NEXT_BUILD_ID}`,
        guess_uncaught_frames: true,
      },
    },
  },
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that only cover browser side is good enough, to keep it simple as possible.

Copy link
Collaborator

@brandondoran brandondoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesmosier thank you so much for taking that time to do this! And @pjaws thanks for your feedback as well!

I just had suggestions for a couple README related tweaks. After those I will merge this.


This is a basic Next.js app (created via `npm init next-app`).

The pertinent files in this PR:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you re-word this just a bit so it doesn't mention "PR"? Maybe just change to "example"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesmosier in the main README, there's a link to the react example. Would mind adding a link to the Next.js example too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! that was a copy/paste from the PR description 😄

updated them both!

@codecov-io
Copy link

Codecov Report

Merging #83 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #83   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           74        74           
  Branches        18        18           
=========================================
  Hits            74        74           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 015c7aa...643ec23. Read the comment docs.

Copy link
Collaborator

@brandondoran brandondoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this contribution @jamesmosier!

@brandondoran brandondoran merged commit 5a6edd5 into thredup:master Mar 20, 2020
@jamesmosier jamesmosier deleted the patch/nextjs-example branch March 20, 2020 20:40
@brandondoran
Copy link
Collaborator

published in [email protected]

github-actions bot pushed a commit that referenced this pull request Oct 16, 2020
# [1.1.0-beta.1](v1.0.2...v1.1.0-beta.1) (2020-10-16)

### Bug Fixes

* **ci:** migrate to semantic-release ([d8ae222](d8ae222))
* **docs:** add devtool to usage example and document ([#78](#78)) ([1705a9b](1705a9b))

### Features

* **examples:** added Next.js example ([#83](#83)) ([5a6edd5](5a6edd5))
* **options:** add encodeFilename flag ([#163](#163)) ([4829ebe](4829ebe)), closes [#162](#162)
* **publicPath:** public path as function ([#58](#58)) ([041d205](041d205))
* **webpack-api:** support webpack 4 hooks API ([#53](#53)) ([cc3b747](cc3b747))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nextjs fn example
4 participants