Title: [Nuxt] Investigate issue with server-side not building correctly (`import` and `import()` are added) · Issue #14514 · getsentry/sentry-javascript · GitHub
Open Graph Title: [Nuxt] Investigate issue with server-side not building correctly (`import` and `import()` are added) · Issue #14514 · getsentry/sentry-javascript
X Title: [Nuxt] Investigate issue with server-side not building correctly (`import` and `import()` are added) · Issue #14514 · getsentry/sentry-javascript
Description: --> scroll down to see the workaround for this issue What is happening? With the Nuxt rollup plugin (which is automatically added by the SDK), the content of sentry.server.config.ts is added to the server entry file (.output/server/index...
Open Graph Description: --> scroll down to see the workaround for this issue What is happening? With the Nuxt rollup plugin (which is automatically added by the SDK), the content of sentry.server.config.ts is added to the...
X Description: --> scroll down to see the workaround for this issue What is happening? With the Nuxt rollup plugin (which is automatically added by the SDK), the content of sentry.server.config.ts is added to ...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/14514
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Nuxt] Investigate issue with server-side not building correctly (`import` and `import()` are added)","articleBody":"**--> scroll down to see the workaround for this issue**\n\n# What is happening?\n\nWith the Nuxt rollup plugin (which is automatically added by the SDK), the content of `sentry.server.config.ts` is added to the server entry file (`.output/server/index.mjs`) and the rest of the server application (either `nitro/nitro.mjs` or `runtime.mjs`) is added via a dynamic `import()`.\n\nIf it is correct, it should look something like this:\n\n```js\n// CORRECT\n// Note: file may have some imports and code related to debug IDs\nSentry.init({\n dsn: \"...\"\n});\n\nimport('./chunks/nitro/nitro.mjs').then(function (n) { return n.r; });\n\nasync function default_sentryWrapped(...args) {\n const res = await import('./chunks/nitro/nitro.mjs').then(function (n) { return n.r; });\n return res.default.call(this, ...args);\n}\n\nexport { default_sentryWrapped as default };\n```\n\nHowever, the build output sometimes looks like this:\n```js\n// WRONG\nimport './chunks/nitro/nitro.mjs'; // \u003c-- server file is added with `import`\n\n/* ... same code as above */\n```\n\nThis is a problem, because Sentry needs to be initialized before any other server-side code is loaded. With ES Modules, this can only happen by dynamically importing (with `import()`) the application to load it afterwards or using the `--import` flag. Sentry is not initialized correctly when there is another, regular `import` of the server-side code.\n\n# Debugging Process\n\nThe following things have been found out already:\n- the issue appears above nitropack 2.10.0 when using pnpm\n- the issue appears above nitropack 2.10.3 when using yarn\n- the issue disappears when deleting the `.git` folder (more on this below)\n- the issue disappears when deleting the contents of `server/middleware`\n- the issue disappears when commenting out [this portion](https://github.com/nitrojs/nitro/blob/8b4a408231bdc222569a32ce109796a41eac4aa6/src/rollup/config.ts#L140-L142) of `nitropack` in the `node_modules` (still needs some investigation if this happens continously)\n\n### Deleting `.git`\n\nThis is very strange, as there is no obvious connection to git. The files and folders listed below are the ones that affect the build output. If any of those are missing, the build output is correct again.\n- HEAD\n- objects (empty)\n- refs\n - heads\n - master\n\n# Workaround\n\nThe current workaround is overriding the version of `nitropack`. As the older version of `nitropack` is still including an old version of `@vercel/nft`, this override has to be added as well:\n\nnpm\n```json\n\"overrides\": {\n \"nitropack\": \"~2.9.7\"\n \"@vercel/nft\": \"^0.27.4\"\n}\n```\n\nyarn\n```json\n\"resolutions\": {\n \"nitropack\": \"~2.9.7\"\n \"@vercel/nft\": \"^0.27.4\"\n}\n```\n\npnpm\n```json\n\"pnpm\": {\n \"overrides\": {\n \"nitropack\": \"~2.9.7\"\n \"@vercel/nft\": \"^0.27.4\"\n }\n}\n```\n","author":{"url":"https://github.com/s1gr1d","@type":"Person","name":"s1gr1d"},"datePublished":"2024-11-27T17:08:16Z","url":"https://github.com/getsentry/sentry-javascript/issues/14514"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4be70a3a-59ad-be20-cfd1-af2ba6cf71f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6EA:377538:800DD6:A861A3:6B04CB03 |
| html-safe-nonce | 7acbe679eb4c1c74e649ee81fbea65991783d7f5b589c277edc1ad41762a30c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkVBOjM3NzUzODo4MDBERDY6QTg2MUEzOjZCMDRDQjAzIiwidmlzaXRvcl9pZCI6IjM4NDI3NjAxODEyOTM1NjY3MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d4a94f74809eff662b6bef616d35c265fccd7cf2a3930df8f560c5e417184d4d |
| hovercard-subject-tag | issue:2699240817 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/14514/issue_layout |
| twitter:image | https://opengraph.githubassets.com/11aa1e81589d55fcc8ec27842381492d7f43c4d9dac319b92416c2525e345543/getsentry/sentry-javascript/issues/14514 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/11aa1e81589d55fcc8ec27842381492d7f43c4d9dac319b92416c2525e345543/getsentry/sentry-javascript/issues/14514 |
| og:image:alt | --> scroll down to see the workaround for this issue What is happening? With the Nuxt rollup plugin (which is automatically added by the SDK), the content of sentry.server.config.ts is added to the... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | s1gr1d |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 63dc19014c621c67306d7899c04c78dcd0d95803 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width