[RUM-15336] Fix preload script resolution#73
Merged
Conversation
bcaudan
reviewed
Mar 30, 2026
fa9b844 to
dd2d558
Compare
581ea66 to
6f29fa0
Compare
bcaudan
reviewed
Mar 31, 2026
a3c8bd3 to
0883656
Compare
bcaudan
previously approved these changes
Apr 1, 2026
Support bundled main processes (Vite, Webpack) by adding multi-strategy preload resolution and a manual preload import path for packaged/bundled apps.
0883656 to
caa7fb9
Compare
bcaudan
approved these changes
Apr 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
When the main process is bundled (Vite, Webpack,...),
__dirnameinregisterPreload()points to the bundler's output directory instead of the SDK'sdist. Sincepreload-auto.cjsisn't copied there, it fails with:Error: ENOENT: no such file or directory, open '.../.vite/build/preload-auto.cjs'This affects any app scaffolded with
npx create-electron-app@latestusing the Vite or Webpack templates.Changes
For unbundled apps, we now try multiple strategies to find preload-auto.cjs — first via
__dirname, then viarequire.resolve. This covers both unbundled and bundled dev scenarios.For bundled + packaged apps (where neither strategy works), we now export the preload bridge as
@datadog/electron-sdk/preload. Users add import@datadog/electron-sdk/preloadto their preload script, and the bundler inlines the bridge code into the app'spreload.js— no external file to find at runtime.A double-registration guard was added to
setupRendererBridge()so that both mechanisms can coexist without conflicts.Checklist