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.

Nextjs - Source mapping failed: A source map could not be applied

See original GitHub issue

Anyone using Next.js and has successfully managed to upload source maps to bugsnag?

I have successfully set up my next.config.js file to upload my source maps to bugsnag using webpack-bugsnag-plugins.

However, bugsnag cannot seem to apply the source map to my code as seen in the screenshot below. Also, release stage is recorded as Production even though the issue is triggered from Staging (I’ve tried setting bugsnag releaseStage to process.env.NODE_ENV and it does not work).

screen shot 2019-01-30 at 2 26 22 pm

next.config.js

const fs = require('fs')
const withSass = require('@zeit/next-sass')
const { BugsnagSourceMapUploaderPlugin } = require('webpack-bugsnag-plugins')

module.exports = withSass({
  webpack: (config, { buildId, dev, isServer }) => {
    const oldEntry = config.entry
    config.entry = function () {
      return oldEntry().then(function (entries) {
        if (entries['main.js']) {
          entries['main.js'].unshift('babel-polyfill')
        }

        return entries
      })
    }

    config.module.rules = config.module.rules.map(rule => {
      if (rule.loader === 'babel-loader') {
        rule.options.cacheDirectory = false
      }
      return rule
    })

    config.devtool = 'source-map'
    for (const plugin of config.plugins) {
      if (plugin['constructor']['name'] === 'UglifyJsPlugin') {
        plugin.options.sourceMap = true
        break
      }
    }

    config.plugins.push(
      new BugsnagSourceMapUploaderPlugin({
        apiKey: 'af3a166c839bf6a0e9304c1bae9e5e24',
        publicPath: '*/',
        overwrite: true
      })
    )

    return config
  },
  generateBuildId: () => {
    const buildId = fs.readFileSync(process.cwd() + '/build/BUILD_ID', 'utf8')
    return buildId.trim()
  },
  poweredByHeader: false
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dallen4commented, Jan 27, 2020

@mattdyoung and anyone who may need it, the example repo for configuring source map uploads to Bugsnag during the build and deployment process can be found here. Please feel free to reach out for any clarifications.

2reactions
carloscuestacommented, Jan 30, 2020

But we can try to kindly remind this, since the fix was pushed “15 months ago”. So maybe reopening an issue to remind that this is a pain for some users will help on releasing this to the next version

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Source Maps | Next.js
Source Maps are enabled by default during development. During production builds, they are disabled to prevent you leaking your source on the client,...
Read more >
Troubleshooting Source Maps for Next.js
For uploaded source maps to be located and applied, the release needs to be created by the CLI or API (and the correct...
Read more >
Error message "DevTools failed to load SourceMap: Could not ...
mine was caused by a webpack-config. I changed the config to include devtool: 'inline-source-map', as aiibe mentioned on github. Just mentioning ...
Read more >
Upload sourcemap to the same URL without am unique ...
Background: I am trying to upload my nextjs sourcemap to the browser UI, everything seems fine the first time.
Read more >
JavaScript Debugging with Sourcemaps - TrackJS
The main purpose of sourcemaps is to aid debugging. Basically, if there's an error in the generated code file, the map can tell...
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