getsentry / sentry-javascript

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

Nuxt module does not take into account "srcDir" for client instrumentation #13330

Open max-arias opened 2 months ago

max-arias commented 2 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

8.25.0

Framework Version

8.25.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

The Sentry module does not seem to take into account the srcDir config, it only uses the buildDir: https://github.com/getsentry/sentry-javascript/blob/master/packages/nuxt/src/module.ts#L30

The current work around is to create a client file both under your srcDir (ie. /src) and in your buildDir (ie /)

With the upcoming Nuxt 4 change where the src files will live in another dir, we should fix this

Expected Result

We should read sentry.client.config from the srcDir without needing a copy in the buildDir

Actual Result

rollup throws an error if there's nothing in "srcDir"

s1gr1d commented 2 months ago

Thanks for already testing the experimental Nuxt SDK and filing this! We will fix this, as we want to be compatible with Nuxt 4!

s1gr1d commented 2 months ago

A follow-up question @max-arias: Why would you want to add the config file in the src directory? Are there any issues with creating the Sentry config along with the Nuxt config in the root directory?

max-arias commented 2 months ago

@s1gr1d Yeah, if I try placing just sentry.client.config.ts at the root of my project, outside src I get a build error. This is after removing .nuxt/ and running a yarn install again.

ℹ Building client...                                                                                                                                                     10:38:17 AM
ℹ vite v5.4.0 building for production...                                                                                                                                 10:38:17 AM
[sentry-vite-plugin] Info: Sending telemetry data on issues and performance to Sentry. To disable telemetry, set `options.telemetry` to `false`.
ℹ ✓ 52 modules transformed.                                                                                                                                              10:38:18 AM

 ERROR  x Build failed in 1.15s                                                                                                                                           10:38:18 AM

[10:38:18 AM]  ERROR  Nuxt Build Error: [vite]: Rollup failed to resolve import "/sentry.client.config.ts" from "virtual:nuxt:/Users/<redacted>/dev/<redacted>/.nuxt/sentry-client-config.mjs".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
build.rollupOptions.external

  This is most likely unintended because it can break your application at runtime.
  If you do want to externalize this module explicitly add it to
  build.rollupOptions.external
  at viteWarn (node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:65463:17)
  at onRollupWarning (node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:65495:5)
  at onwarn (node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:65158:7)
  at node_modules/rollup/dist/es/shared/node-entry.js:18625:13
  at Object.logger [as onLog] (node_modules/rollup/dist/es/shared/node-entry.js:20280:9)
  at ModuleLoader.handleInvalidResolvedId (node_modules/rollup/dist/es/shared/node-entry.js:19215:26)
  at node_modules/rollup/dist/es/shared/node-entry.js:19173:26
s1gr1d commented 2 months ago

Thanks for clarifying, I'll take a look!