Skip to content

[RUM-15336] Fix preload script resolution#73

Merged
cdn34dd merged 1 commit into
mainfrom
carlosnogueira/RUM-15336/fix-preload-resolution
Apr 1, 2026
Merged

[RUM-15336] Fix preload script resolution#73
cdn34dd merged 1 commit into
mainfrom
carlosnogueira/RUM-15336/fix-preload-resolution

Conversation

@cdn34dd

@cdn34dd cdn34dd commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Motivation

When the main process is bundled (Vite, Webpack,...), __dirname in registerPreload() points to the bundler's output directory instead of the SDK's dist. Since preload-auto.cjs isn'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@latest using the Vite or Webpack templates.

Changes

For unbundled apps, we now try multiple strategies to find preload-auto.cjs — first via __dirname, then via require.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/preload to their preload script, and the bundler inlines the bridge code into the app's preload.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

  • Tested locally (playground)
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated related documentation.

@cdn34dd cdn34dd marked this pull request as ready for review March 30, 2026 09:33
@cdn34dd cdn34dd requested a review from a team as a code owner March 30, 2026 09:33
Comment thread src/bridge/registerPreload.ts Outdated
@cdn34dd cdn34dd force-pushed the carlosnogueira/RUM-15336/fix-preload-resolution branch from fa9b844 to dd2d558 Compare March 31, 2026 11:46
@cdn34dd cdn34dd requested a review from bcaudan March 31, 2026 11:47
@cdn34dd cdn34dd force-pushed the carlosnogueira/RUM-15336/fix-preload-resolution branch 2 times, most recently from 581ea66 to 6f29fa0 Compare March 31, 2026 13:24
Comment thread README.md Outdated
Comment thread src/bridge/registerPreload.ts Outdated
Comment thread package.json
@cdn34dd cdn34dd force-pushed the carlosnogueira/RUM-15336/fix-preload-resolution branch 2 times, most recently from a3c8bd3 to 0883656 Compare March 31, 2026 17:02
bcaudan
bcaudan previously approved these changes Apr 1, 2026
Comment thread rollup.config.mjs Outdated
Support bundled main processes (Vite, Webpack) by adding multi-strategy
preload resolution and a manual preload import path for packaged/bundled
apps.
@cdn34dd cdn34dd force-pushed the carlosnogueira/RUM-15336/fix-preload-resolution branch from 0883656 to caa7fb9 Compare April 1, 2026 13:12
@cdn34dd cdn34dd merged commit 842a9ad into main Apr 1, 2026
14 checks passed
@cdn34dd cdn34dd deleted the carlosnogueira/RUM-15336/fix-preload-resolution branch April 1, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants