require() in webpage doesn't use proper relative paths #276

Closed
opened 2026-01-29 16:35:33 +00:00 by claunia · 3 comments
Owner

Originally created by @The-MAZZTer on GitHub (Feb 10, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

I am using electornize start to start my project from my project folder. I am using Electron.NET 0.0.11 under .NET Core 2.1.6 (I was going to use 2.2 but I got some warnings suggesting Electron.NET wasn't yet compatible).

I get "cannot load module" even though I can confirm the module is at the proper location.

For example for the url http://localhost:8001/ I have an index.html with the JavaScript: require("./scripts/main");

Trying to access https http://localhost:8001/scripts/main.js manually from a browser properly returns the JavaScript file I want it to load.

I pulled in these files from a normal Electron project where they worked.

I did some JS debugging in both Electron and Electron.NET. There is a parent value passed in which appears to contain the path of the script that is executing, which allows require() to resolve relative paths.

In Electron.NET, this value is INCORRECTLY set as "<ProjectDir>\obj\Host\node_modules\electron\dist\resources\electron.asar\renderer\init.js". It appears this is the path the webpage thinks it is at in the Module class which is responsible for creating a proper require command and tracking its current path and a bunch of other stuff. I am seeing this value propagate from Module.prototype._compile.

Originally created by @The-MAZZTer on GitHub (Feb 10, 2019). Originally assigned to: @GregorBiswanger on GitHub. I am using electornize start to start my project from my project folder. I am using Electron.NET 0.0.11 under .NET Core 2.1.6 (I was going to use 2.2 but I got some warnings suggesting Electron.NET wasn't yet compatible). I get "cannot load module" even though I can confirm the module is at the proper location. For example for the url http://localhost:8001/ I have an index.html with the JavaScript: require("./scripts/main"); Trying to access ~~https~~ http://localhost:8001/scripts/main.js manually from a browser properly returns the JavaScript file I want it to load. I pulled in these files from a normal Electron project where they worked. I did some JS debugging in both Electron and Electron.NET. There is a parent value passed in which appears to contain the path of the script that is executing, which allows require() to resolve relative paths. In Electron.NET, this value is INCORRECTLY set as "\<ProjectDir\>\obj\Host\node_modules\electron\dist\resources\electron.asar\renderer\init.js". It appears this is the path the webpage thinks it is at in the Module class which is responsible for creating a proper require command and tracking its current path and a bunch of other stuff. I am seeing this value propagate from Module.prototype._compile.
claunia added the question label 2026-01-29 16:35:33 +00:00
Author
Owner

@JimmyTheJ commented on GitHub (Feb 11, 2019):

You can't use HTTPS with electronNET.

@JimmyTheJ commented on GitHub (Feb 11, 2019): You can't use HTTPS with electronNET.
Author
Owner

@The-MAZZTer commented on GitHub (Feb 13, 2019):

Sorry, I meant HTTP. I am not using HTTPS in Electron.NET.

@The-MAZZTer commented on GitHub (Feb 13, 2019): Sorry, I meant HTTP. I am not using HTTPS in Electron.NET.
Author
Owner

@GregorBiswanger commented on GitHub (May 16, 2019):

Please include the following base href in your index file:
<base href="./">

Note that usually the wwwroot directory is directly mapped and your relevant files are there.

@GregorBiswanger commented on GitHub (May 16, 2019): Please include the following base href in your index file: `<base href="./">` Note that usually the wwwroot directory is directly mapped and your relevant files are there.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#276