Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
151 views
in Technique[技术] by (71.8m points)

javascript - Running two scripts in Electron MAIN process

First off, I want to clarify that I want to require a script in the MAIN process, not the renderer.

my file structure is the following:

| main.js (what electron runs)
| js
| | app.js ( what I want to require)

I would like to use the functions/classes in app.js to run in the main process without putting it in main.js (app.js is huge and I don't want to clutter main.js)

I have tried

require('js/app.js')

but it returns the following:

App threw an error during load
TypeError: Cannot read property 'BrowserWindow' of undefined
    at Object.<anonymous> (/Users/siddharth/dev/DJTorsten/js/app.js:7:39)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1173:10)
    at Module.load (internal/modules/cjs/loader.js:992:32)
    at Module._load (internal/modules/cjs/loader.js:885:14)
    at Function.f._load (electron/js2c/asar_bundle.js:5:12738)
    at Module.require (internal/modules/cjs/loader.js:1032:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/siddharth/dev/DJTorsten/main.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:1152:30)

which from debugging I can tell it is from app.js. From what I can tell, it is not loading node integration.

My question is that can I do something to load node integration or is there another solution to loading app.js in the main process.

question from:https://stackoverflow.com/questions/65836515/running-two-scripts-in-electron-main-process

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...