When updating the npm package "handbrake-js" in an Electron application, an error occurs while attempting to load the preload script. The error message states that the URL must be of scheme file. The issue prevents the preload script from being loaded correctly.
Error log:
node:electron/js2c/renderer_init:73 Unable to load preload script: /Users/user/Documents/handbrake_update/electron/app/preload.js
node:electron/js2c/renderer_init:73 TypeError: The URL must be of scheme file
at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
at new NodeError (node:internal/errors:372:5)
at Object.fileURLToPath (node:internal/url:1424:11)
at getModulePaths (/Users/user/Do…ist/index.cjs:12:26)
at Object.<anonymous> (/Users/user/Do…ist/index.cjs:17:36)
at Object.<anonymous> (/Users/user/Do…ist/index.cjs:676:3)
...
What I tried:
- Change the preload path to be of scheme file (add "file://" to beginning of preload path)
const argsBrowserWindow = {
webPreferences: {
preload: path.join(__dirname, 'preload.js') ,
...
},
...
}
Which gets rid of the error above but breaks the preload and causes the following:
[40093:0615/110609.094749:ERROR:web_contents_preferences.cc(255)] preload script must have absolute path.
- Reinstall all packages
- Rebuild the handbrake-js package
setup:
- process.platform = darwin
- process.arch = arm64
- update from handbrake-js@^5.0.3 to [email protected]
- node version: v19.1.0
- "@electron/rebuild": "^3.2.9"
- "electron": "^21.3.1"
Reinstalling the previous version of the handbrake-js npm gets rid of all errors.
Any help on finding out the reason of this happening would be appreciated, thank you in advance.