question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

preload script must have absolute path

See original GitHub issue

Versions + Platform

  • SDK version - @sentry/electron@v3.0.7
  • Electron version - electron@v18.2.0
  • Platform - macOS

Description

There are lots of error messages coming from the main process:

[22375:0526/171429.459534:ERROR:session_preferences.cc(38)] preload script must have absolute path: ../../common/temp/node_modules/.pnpm/@sentry+electron@3.0.7/node_modules/@sentry/electron/esm/preload/index.js
Screen Shot 2022-05-26 at 5 16 58 PM

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
timfishcommented, Jun 21, 2022

Ah, so it looks like webpack does replace these with relative strings!

I will poke around to see if something can be done on the webpack config side

It would be nice to fix this regardless of webpack config.

Because the main process is bundled, these files will not exist and the SDK will fall back to using a custom protocol so you can avoid this for now by setting the IPCMode manually: https://github.com/getsentry/sentry-electron/blob/00e7a4608e452d4447cc50cadef682af6cda6e28/test/e2e/test-apps/javascript/renderer-error-protocol/src/main.js#L9

We could convert the relative path to absolute, but because the file does not exist it will result in unnecessary file system access.

1reaction
damienallencommented, Jun 21, 2022

Interesting, I will poke around to see if something can be done on the webpack config side. FYI, tere’s what my webpack bundle looks like with the relative paths:

_addPreloadToSessions(options) {
        let path = undefined;
        try {
            path = (0,_electron_normalize__WEBPACK_IMPORTED_MODULE_3__.rendererRequiresCrashReporterStart)()
                ? /*require.resolve*/(/*! ../../preload/legacy.js */ "./node_modules/@sentry/electron/esm/preload/legacy.js")
                : /*require.resolve*/(/*! ../../preload/index.js */ "./node_modules/@sentry/electron/esm/preload/index.js");
        }
        catch (_) {
            //
        }
        if (path && typeof path === 'string' && (0,fs__WEBPACK_IMPORTED_MODULE_1__.existsSync)(path)) {
            for (const sesh of options.getSessions()) {
                // Fetch any existing preloads so we don't overwrite them
                const existing = sesh.getPreloads();
                sesh.setPreloads([path, ...existing]);
            }
        }
        else {
            _sentry_utils__WEBPACK_IMPORTED_MODULE_5__.logger.log('The preload script could not be injected automatically. This is most likely caused by bundling of the main process');
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

preload script not loaded in packaged app - Stack Overflow
Preload script needs to be specified as an absolute path. Thus it will differ from the time you're running it in development versus...
Read more >
Electron Adventures: Episode 10: Preload Script
For some reason Electron really wants preload path to be absolute path ... In the frontend script, we just need to change two...
Read more >
Migrating to v3 · Issue #370 · getsentry/sentry-electron - GitHub
preload script must have absolute path : ./node_modules/@sentry/electron/esm/preload/index.js. I'm on Electron: 15.2.0 and using ...
Read more >
Unable to require path and fs modules in preload script - Reddit
I have been trying to resolve this issue for the last 3 hours and am unable to make any progress. The preload script...
Read more >
Using Preload Scripts - Electron
In this part of the tutorial, you will learn what a preload script is and how to use one to securely expose privileged...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found