Open lucassilvas1 opened 1 year ago
Update: I don't get the "Unable to load preload script" error when I comment out everything inside preload.ts
, so it seems to be something in preload.ts
that's causing it.
I suspect it's to do with the second error in the screenshot: "Error: module not found: ./bridge", but I still don't know why, since bridge.ts
is in the same folder as preload.ts
, there's nothing special about those files either, I export an object from bridge.ts
: export default bridge;
, that I then import in preload.ts
so I can expose it to the renderer process:
import { ipcRenderer, contextBridge } from "electron";
import bridge from "./bridge";
contextBridge.exposeInMainWorld("bridge", bridge);
VS Code doesn't complain about a module not found or anything, the type hints work and everything.
Update: I managed to fix the first two problems, "Unable to load preload script" and "Error: module not found: ./bridge" by temporarily setting webPreferences.sandbox
to false
when creating the window. Apparently you can't import anything into the preload script with it enabled, so I'll have to move everything from src/electron/bridge.ts
to src/electron/preload.ts
, or somehow bundle all the code into the preload script during build.
Now I need to fix the third problem, you can see it in the screenshot above: "DevTools failed to load source map: Could not parse content for file:///C:/Users/Lucas/Javascript/[APP-NAME]/output/win-unpacked/resources/app.asar/dist/**public**/preload.js.map: Unexpected end of JSON input
.
I highlighted public there for a reason, DevTools is looking for the source maps in the wrong place, and I don't know why that is, the source map for the preload script is located at file:///C:/Users/Lucas/Javascript/[APP-NAME]/output/win-unpacked/resources/app.asar/dist/**electron**/preload.js.map
.
This is also happening with the source maps on the Svelte side, if I click on an error in the console, it takes me to a blank file.
This is the exact problem I'm having, no response three years later.
Didn't manage to fix the source map problem, so temporarily I'm using inline source maps to avoid running into it.
Hi,
I'm trying to convert an existing (and fully working) Electron + Svelte project to use TypeScript, so I decided to follow your tutorial on Medium.
Problem is, when I launch the executable I get the error in the title, like the path is incorrect. I'm not sure what the problem is.
This is my folder structure:
I load the preload script from
src/electron/index.ts
:This is my root
tsconfig.json
:I had to change the
rootDir
tosrc
and not justsrc/electron
like in your example, because I import some stuff fromserver
toelectron/index.ts
.Here's the
tsconfig.json
insidesrc/electron
:This is my
package.json
, omitting irrelevant properties:Notice
main
is set todist/electron/index.js
, I think that's correct, since after building, the file actually ends up there.Do you have any idea what I'm doing wrong here? Stack Overflow hasn't been much help.
This is what I get in the console when Electron launches:
Inside
src/electron/index.ts
I'm also logging__dirname, join(__dirname, "preload.js")
to the console, and this is what I get when I launch:C:\Users\Lucas\Javascript\[APP NAME]\output\win-unpacked\resources\app.asar\dist\electron C:\Users\Lucas\Javascript\[APP NAME]\output\win-unpacked\resources\app.asar\dist\electron\preload.js
That seems correct to me.Any advice you could give would be much appreciated.