简体   繁体   中英

Node require() inside Angular 2 App with Electron

I am trying to use electron's remote to set application menus etc. However, the angular polyfills catch the require('electron).remote and log require is not a function to the console. (Which makes sense as it would not be a function inside a normal web environment.)

Is there a way to prevent this?

According to the electron docs, the require collision can be overridden using this code before the angular and systemjs polyfills:

<script>
    window.nodeRequire = require;
    delete window.require;
    delete window.exports;
    delete window.module;
</script>

More info here: http://electron.atom.io/docs/v0.37.3/faq/electron-faq/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM