Title: @sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler `main` is a package specifier · Issue #24522 · getsentry/sentry-javascript · GitHub
Open Graph Title: @sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler `main` is a package specifier · Issue #24522 · getsentry/sentry-javascript
X Title: @sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler `main` is a package specifier · Issue #24522 · getsentry/sentry-javascript
Description: Description sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry code, and the plugin logs no warning. @c...
Open Graph Description: Description sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry ...
X Description: Description sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry ...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/24522
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler `main` is a package specifier","articleBody":"### Description\n\n`sentryCloudflareVitePlugin()` does not wrap the Worker when `main` in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry code, and the plugin logs no warning.\n\n`@cloudflare/vite-plugin` supports this config, and [vinext](https://github.com/cloudflare/vinext) generates it by default with `vinext init --platform=cloudflare`:\n\n```jsonc\n// wrangler.jsonc\n{\n \"main\": \"vinext/server/fetch-handler\",\n // ...\n}\n```\n\n```ts\n// vite.config.ts\nexport default defineConfig({\n plugins: [\n vinext(),\n cloudflare({ viteEnvironment: { name: \"rsc\", childEnvironments: [\"ssr\"] } }),\n sentryCloudflareVitePlugin(),\n ],\n});\n```\n\nTested with `@sentry/cloudflare@11.0.0-rc.0`, `@cloudflare/vite-plugin@1.56.0`, `wrangler@4.135.0`, `vinext@1.0.0-beta.10` and Vite 8.3.\n\n### Cause\n\n`resolveWranglerConfig()` calls `unstable_readConfig()` without `preserveOriginalMain` ([wranglerConfig.ts#L70](https://github.com/getsentry/sentry-javascript/blob/beca211185/packages/cloudflare/src/vite/wranglerConfig.ts#L70)). Wrangler then resolves every `main` as a path relative to the config file:\n\n```\nmain: \"vinext/server/fetch-handler\"\n-> \u003cproject>/vinext/server/fetch-handler (file does not exist)\n```\n\n`autoInstrument.ts` compares this path with the module IDs in `transform` ([L75](https://github.com/getsentry/sentry-javascript/blob/beca211185/packages/cloudflare/src/vite/autoInstrument.ts#L75)), so no module matches. `resolveInstrumentFile()` also looks for `instrument.server.*` in the directory of this path ([instrumentFile.ts#L23](https://github.com/getsentry/sentry-javascript/blob/beca211185/packages/cloudflare/src/vite/instrumentFile.ts#L23)), and a package entry has no such file.\n\n`@cloudflare/vite-plugin` handles the same value differently:\n\n1. It reads the config with `unstable_readConfig(..., { preserveOriginalMain: true })`.\n2. `maybeResolveMain()` makes `main` absolute only when it ends with a JS or TS extension.\n3. It resolves the entry with Vite: `await this.resolve(workerConfig.main)`.\n\n### Workaround\n\nAdd a local entry that re-exports the package entry, and set `main` to it. Put `instrument.server.ts` in the same directory:\n\n```ts\n// worker/index.ts\nimport handler from \"vinext/server/fetch-handler\";\n\nexport default handler;\n```\n\n```jsonc\n{ \"main\": \"./worker/index.ts\" }\n```\n\n### Proposed fix\n\n- Read the config with `preserveOriginalMain: true`, and keep a package specifier unchanged.\n- Resolve `main` with `this.resolve()` (for example in `buildStart`, or lazily in `transform`), and compare the resolved module ID.\n- When the resolved entry is in `node_modules`, look for `instrument.server.*` in the Wrangler config directory (the Vite root) and not next to the entry.\n- Log a warning when `main` does not resolve to a module that the plugin transforms, so the failure is not silent.\n- Add a test fixture where `main` is a package specifier.\n","author":{"url":"https://github.com/JPeer264","@type":"Person","name":"JPeer264"},"datePublished":"2026-09-19T09:33:08Z","url":"https://github.com/getsentry/sentry-javascript/issues/24522"}
| 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:29be75ac-87e2-cc2e-a722-107d7abf85f4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC72:15A4DC:1674942:1E0A190:6B042B3C |
| html-safe-nonce | de17c61605864128a155efeb16a6f4021ec8ce743d2db768d1ef8462e223e3c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzcyOjE1QTREQzoxNjc0OTQyOjFFMEExOTA6NkIwNDJCM0MiLCJ2aXNpdG9yX2lkIjoiODE2NzkxMTM2NDk4ODUxMzA4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bcaac1e789a71271208ca8c9196ec5363c9617ef835efda924eca6ffa2a8ff5b |
| hovercard-subject-tag | issue:5509108039 |
| 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/24522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/64302790caa07d6023a7f1e13e9621a64bfe348144f277417508fc9dc2ae8e6a/getsentry/sentry-javascript/issues/24522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/64302790caa07d6023a7f1e13e9621a64bfe348144f277417508fc9dc2ae8e6a/getsentry/sentry-javascript/issues/24522 |
| og:image:alt | Description sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JPeer264 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| 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 | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| 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