saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.98k stars 229 forks source link

global is not defined #318

Closed Ahtisham-01 closed 1 year ago

Ahtisham-01 commented 1 year ago
cellis commented 1 year ago

Don't use context isolation ( I agree with the Electron team's rationale for contextIsolation: true, IF you EVER plan to load 3rd party websites or even your own website that has 3rd party javascript running, as they could access your IPC calls ). However if you treat the app as a secure app and never load third party websites or scripts, then it's fine to turn off.

If you still want to go ahead, modify the next.config.js:

    if (!isServer) {
      config.target = 'electron-renderer';
      config.node = {
        __dirname: true,
      };
    }

    config.output.globalObject = 'this';
    ...
Ahtisham-01 commented 1 year ago

Thanks ! its working

On Wed, Feb 1, 2023 at 1:04 AM Cameron Ellis @.***> wrote:

Don't use context isolation ( I agree with the Electron team's rationale for this, IF you EVER plan to load 3rd party websites or even your own website that has 3rd party javascript running, as they could access your IPC calls ). However if you treat the app as a secure app and never load third party websites or scripts, then it's fine to turn off.

If you still want to go ahead, modify the next.config.js:

if (!isServer) {
  config.target = 'electron-renderer';
  config.node = {
    __dirname: true,
  };
}

config.output.globalObject = 'this';
...

— Reply to this email directly, view it on GitHub https://github.com/saltyshiomix/nextron/issues/318#issuecomment-1410990365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ6UOR2KIKLQD3SXRR7LA7TWVFV4TANCNFSM6AAAAAAUMEJ6XQ . You are receiving this because you authored the thread.Message ID: @.***>

saltyshiomix commented 1 year ago

@Ahtisham-01 Sorry for late reply 🙇

May be we can remove config.target = 'electron-renderer' in next.config.js.

Before

module.exports = {
  trailingSlash: true,
  images: {
    unoptimized: true,
  },
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.target = 'electron-renderer'
    }

    return config
  },
}

After

/** @type {import('next').NextConfig} */
module.exports = {
  trailingSlash: true,
  images: {
    unoptimized: true,
  },
  webpack: (config) => {
    return config
  },
}