Using require when electron app is packaged in an asar
Asked Answered
A

1

6

In my main.js, I have:

var mainFrm = require('./MainFrm');

This works fine except when the application is packaged as an asar file. I get a 'Cannot find module' error.

The documentation states to use the following:

require('/path/to/example.asar/dir/module.js');

I tried that but got the same error. Where does the path begin when using the above? Does path start with electron.exe is? Also, if I use require('/resources/app.asar/MainFrm.js') what path do I use for OS X apps since the Resources folder is in a different location? What path should I use during development/debugging (i.e. not inside of an asar)

Anthracoid answered 7/4, 2016 at 22:0 Comment(0)
M
1

I think you may have 2 issues. First, you may need to be explicit about the file extension, thus looking for MainFrm.js, not just MainFrm. Second, try using resolve to determine the name relative to the current directory.

One way to resolve this is to resolve the path at runtime, like this:

    var mainFrm = require("path").resolve(__dirname, "./MainFrm.js");

Try some combinations of that and see if it doesn't help.

Mansion answered 20/1, 2017 at 0:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.