Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isDev is always true #21

Closed
kimgysen opened this issue Nov 24, 2019 · 3 comments
Closed

isDev is always true #21

kimgysen opened this issue Nov 24, 2019 · 3 comments

Comments

@kimgysen
Copy link

My npm script looks as follows:

"start:prod": "cross-env NODE_ENV=production && electron dist/main.js"

main.js:

import isDev from 'electron-is-dev';

app.on('ready', () => {
  console.log('isDev', isDev);
  if (!isDev) {
    const {session} = require('electron');
    session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
      callback({responseHeaders: `default-src http: ws:`})
    })
  }
  const win = createWindow();
  createMenu(win);
});

The console outputs:

isDev true

I have some trouble understanding the use of this npm package which seems to be used a lot.
When setting NODE_ENV, I expect just being able to use process.env.NODE_ENV in my code as I'm used to, and it does seem to work.
Why do we need another environment variable (?).

My bundle is packaged with webpack, not sure if this may have anything to do with it, but I wouldn't expect it to.

const path = require('path');

module.exports = {
  entry: "./src/server/main.js",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, '../../dist')
  },
  mode: 'production',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: "babel-loader"
      }
    ]
  },
  node: {
    __dirname: false,
    __filename: false
  },
  target: "electron-main"
};

@sindresorhus
Copy link
Owner

sindresorhus commented Jan 1, 2020

Try to log what electron.app.isPackaged reports. electron-is-dev uses that underneath and it sounds like that is reporting always true for you too, which means the problem is either your build script or Electron itself. If it's Electron, you should open an issue on the Electron issue tracker.

@danst3in
Copy link

My understanding is that electron.app.isPackaged will only return true if you have packaged the file for example with electron-builder and then run the Electron app from the executable file that is produced. This has made it time consuming for me to test other items that behave differently in prod vs. dev, but at least that seems to consistently work.

@kimgysen
Copy link
Author

I am not currently working on this project. I will close this issue for now; if someone else wants to re-open it, feel free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants