getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Sentry nextjs plugin not uploading source maps #3889

Closed cyrus-za closed 3 years ago

cyrus-za commented 3 years ago

Package + Version

Version:

6.10.0

Description

Error:

error: .next/: IO error for operation on .next/: No such file or directory (os error 2)

This happens when trying to build the nextjs app and it results in no source maps being uploaded, but the build still passes.

This used to work and I am not sure what broke it around 2 weeks ago (didn't realise it was a problem until we started tackling sentry errors and found no source maps for these apps).

Background info

This is a monorepo using nx workspaces and consists of multiple nextjs apps, all of which are experiencing this bug.

I reached out to the vercel and nx team and they are stating that it is expected that it will not find the .next directory as we got a monorepo setup and our apps go in dist/appName/.next so it appears that we need to somehow configure the sentry webpack plugin (which we use in next.config.js) to upload the sourcemaps. I checked the docs and it is not clear how to do this.

next.config.js

// eslint-disable-next-line @typescript-eslint/no-var-requires
const withNx = require('@nrwl/next/plugins/with-nx')
const { withSentryConfig } = require('@sentry/nextjs')

const NODE_ENV = process.env.NODE_ENV
const VERCEL_ENV = process.env.VERCEL_ENV ?? 'development'

const nextConfig = {}

module.exports =
  NODE_ENV === 'production'
    ? withNx(withSentryConfig(nextConfig, { deploy: { env: VERCEL_ENV } }))
    : withNx(nextConfig)

Full error message on verce

image

Vercel settings

image
lobsterkatie commented 3 years ago

Hi, @cyrus-za. Thanks for reporting this. I believe it's related to https://github.com/getsentry/sentry-javascript/issues/3854. Does that match your understanding?

cyrus-za commented 3 years ago

Thanks that looks like the exact issue. Closing this one so we can keep the discussion going there

vdhpieter commented 2 years ago

@cyrus-za does this work for you? For me in still doesn't work with NX :( I did find a way to make it work though. Will make a PR soon

vdhpieter commented 2 years ago

In the end a PR was not needed just adding: include: 'dist/apps/<app-name>/.next' to the sentry webpack config did the trick. The documentation for this could be improved though 😉