Fabio Marzocca
Fabio Marzocca

Reputation: 1677

webview: require is not defined

In my electron app I am setting a webview. This is a snippet from index.html:

  <webview
    class="hide"
    preload="./preload.js"
    nodeintegration
  ></webview>

  <script>
    require('./renderer.js');
  </script>

In main.js I have set nodeIntegration:false for the BrowserWindow, but the app doesn't start, as I get this error in webview's console:

Uncaught ReferenceError: require is not defined

If I remove nodeIntegration:false from main.js, it works, but I don't want to expose node API.

(P.S.: the remote web app pointed by the webview is using jQuery. Maybe a conflict?)

Upvotes: 0

Views: 2288

Answers (1)

mJehanno
mJehanno

Reputation: 866

If you remove nodeIntegration : false command like require won't be set.

It seems like you have 2 possibilities :

  • let nodeIntegration: false and deal with it

  • call your js file as if you were in browser : <script src="pathToFile"></script>

https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron here they explain what really does nodeIntegration

Upvotes: 1

Related Questions