quasar: Electron - Node Integration = false, Production Build Fails

Describe the bug Using Quasar Electron Mode: with Node Integration False fails on production build using electron-builder.

// quasar.conf.js
      nodeIntegration: false,
// electron-main.js
      nodeIntegration: QUASAR_NODE_INTEGRATION,
      nodeIntegrationInWorker: QUASAR_NODE_INTEGRATION,
      preload: path.resolve(__dirname, 'electron-preload.js'),

The dev version works and loads fine, but on production build, i get the following error:

Uncaught ReferenceError: __dirname is not defined at Object.<anonymous> (vendor.js:formatted:60347)

Diving Deeper: The error is initiated at line APP_URL, I suspect this is a webpack config error, since for the same project and same code, SPA build (both prod and dev) works just fine.

Also, the main process and renderer process both do not throw any error, the problem just lies in the vendors.js chunk emitted for the app itself.

Also another project initiated some time before (earlier versions) used to work fine too.

e.exports = f(Object({
                NODE_ENV: "production",
                CLIENT: !0,
                SERVER: !1,
                DEV: !1,
                PROD: !0,
                MODE: "electron",
                **APP_URL: "file://" + __dirname + "/index.html",**
                VUE_ROUTER_MODE: "hash",
                VUE_ROUTER_BASE: ""
            }).NODE_NDEBUG)

What does not work Setting up same env variable in quasar.conf.js with blank JSON string to overwrite the default value.

      env: ctx.dev
        ? { }
        : { APP_URL: JSON.stringify('') },

Expected behavior Should probably extend SPA config without modification on Node Integration = False.

Platform (please complete the following information): OS: Win 10.0.17134 Yarn: 1.22.4 Browsers: Chrome 81.0.4044.122 Electron: 8.2.3 Electron-Builder: 22.5.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@webnoob and @pdanpdan, there is one new error appearing though. With nodeIntegration: false, the following script tag should not be added to index.html by default webpack config.

Only happens in production env. Should I open a new issue for that?

<script>window.__statics = __dirname</script>

The renderer now throws the following error:

Uncaught ReferenceError: __dirname is not defined  at index.html:1

@newCodeRunner Check @pdanpdan commits above.

Use: process.env.QUASAR_NODE_INTEGRATION instead of QUASAR_NODE_INTEGRATION

I created an electron project from scratch and saw that now this QUASAR_NODE_INTEGRATION is set to process.env.QUASAR_NODE_INTEGRATION.