Repository navigation
fix(cloudflare): Run build-time instrumentation in vite dev #25777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JPeer264
wants to merge
2
commits into
jp/orchestrion-transform-sourcemap-sources
from
jp/cloudflare-vite-dev-instrumentation
+374
−50
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is function is gonna cause a crash if it's used in a node bundle with vite.
On Vite 6 and 7, the dependency optimizer uses
platform: 'node'for any server environment that is notwebworker(the defaultssrenvironment of every Node SSR framework). For that platform, Vite adds this banner to every optimized file:The new esbuild plugin makes the optimizer bundle
@sentry/server-utils(and@sentry/core) into the pre-bundled dependency.Two lines in
depOptimizerEsbuildPlugincause this. Line 112 (upstream.setup(build)) adds the transform, which puts an import of@sentry/server-utilsinto each instrumented module. Line 107 then resolves that import to a file path (toEsmEntry(resolved.path)), so esbuild bundles the file instead of leaving the import external. The@sentry/server-utilsESM build has its own top-levelimport { createRequire } from "module", and esbuild cannot rename around a text banner. The result is a file that doesn't parse:Cloudflare is not affected, because
@cloudflare/vite-pluginsetsplatform: 'neutral', which has no banner. Withplatform: 'neutral'the Vite 6/7 ESM case loads and fires the channel.Suggestion: scope the dev optimizer plugins to the case this PR targets. Two options:
build.initialOptions.platform, sosetup(line 91) can return before it reaches lines 96-112. The existing duplicate-instance check here already returns early in the same place, so the new check can go next to it:PluginOptionsthatsentryCloudflareVitePluginsets, so the other SDKs keep today'sservebehavior. The PR title saysfix(cloudflare), and the comment at lines 205-207 names@cloudflare/vite-pluginas the reason. An opt-in would make the change match that scope. It would also avoid the side effects on Node SSR envs. This option touches three places: the new field inPluginOptions(packages/server-utils/src/orchestrion/bundler/options.ts), theservebranch at line 208 ofvite.ts(returnnullwhen the option is off), and thesentryOrchestrionPlugin({ ... })call atpackages/cloudflare/src/vite/index.tsline 88.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna check. I like the opt-in method.