sindresorhus / electron-debug

Adds useful debug features to your Electron app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find module 'electron-debug'

daviddelusenet opened this issue · comments

I'm trying to add electron-debug to my Electron application. These are the contents of my electron.js file:

const { app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');
const electronDebug = require('electron-debug');

electronDebug({
  enabled: true
});

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

function createWindow() {
  // Create the browser window.
  win = new BrowserWindow({
    fullscreen: true
  });

  // and load the index.html of the app.
  win.loadURL(url.format({
    pathname: path.join(__dirname, './../dist/index.html'),
    protocol: 'file:',
    slashes: true
  }));

  // Open the DevTools (only during development).
  if (process.env.ELECTRON_ENV === 'dev') {
    win.webContents.openDevTools();
  }

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null;
  });
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow();
  }
});

And I've this in my package.json:

"build": {
  "appId": "ds.video.wall",
  "mac": {
    "category": "public.app-category.video"
  },
  "files": [
    "src/electron.js",
    "dist/index.html",
    "dist/app.min.js",
    "dist/app.min.css",
    "dist/assets/**",
    "node_modules/electron-debug/index.js"
  ]
}

However, when I start my application I get the following error:

Uncaught Exception:
Error: Cannot find module 'electron-debug'
    at Module._resolveFilename (module.js:470:15)
    at Function.Module._resolveFilename (/Users/lusenet/Development/ds-video-wall/dist/mac/ds-video-wall.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/lusenet/Development/ds-video-wall/dist/mac/ds-video-wall.app/Contents/Resources/app.asar/src/electron.js:4:23)
    at Object.<anonymous> (/Users/lusenet/Development/ds-video-wall/dist/mac/ds-video-wall.app/Contents/Resources/app.asar/src/electron.js:63:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

I've also tried the following way of importing electron-debug:

require('electron-debug')({
  enabled: true
});

This leads to the same error.

Did you install latest version of the package?
What do you get if you ls node_modules/electron-debug ?

This is in my package.json: "electron-debug": "^1.5.0"

When I execute ls node_modules/electron-debug:

Davids-MacBook-Pro:ds-video-wall lusenet$ ls node_modules/electron-debug/
index.js	license		package.json	readme.md

Could you paste or link ypour complete package.json?
What is exactly that "build" section you spoke about?
I think there is something wrong in the way you're packaging your app.

Sure, no problem!

Personally I think it has to do with this not being compatible with the latest Webpack/Babel/ES6 stuff.

This is my package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "src/electron.js",
  "build": {
    "appId": "ds.video.wall",
    "mac": {
      "category": "public.app-category.video"
    },
    "files": [
      "src/electron.js",
      "dist/index.html",
      "dist/app.min.js",
      "dist/app.min.css",
      "dist/assets/**"
    ]
  },
  "scripts": {
    "start": "npm run build:dev",
    "start:electron": "ELECTRON_ENV=dev ./node_modules/.bin/electron src/electron.js",
    "build:dev": "BABEL_ENV=dev node_modules/.bin/webpack-dev-server --env=dev",
    "build:prod": "BABEL_ENV=prod node_modules/.bin/webpack --env=prod",
    "pack": "electron-builder --dir",
    "dist": "BABEL_ENV=prod node_modules/.bin/webpack --env=prod && electron-builder",
    "postinstall": "electron-builder install-app-deps",
    "test": "jest",
    "test:update": "jest -u",
    "lint:css": "stylelint './src/**/*.js'"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "keywords": [
    "react"
  ],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-eslint": "^8.1.2",
    "babel-jest": "^22.0.4",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "compression-webpack-plugin": "^1.1.3",
    "css-loader": "^0.28.7",
    "electron": "1.8.2",
    "electron-builder": "^19.52.1",
    "electron-debug": "^1.5.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "eslint": "^4.14.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.5.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "html-webpack-harddisk-plugin": "^0.1.0",
    "html-webpack-plugin": "^2.30.1",
    "jest": "^22.0.4",
    "jest-styled-components": "^4.11.0-0",
    "node-sass": "^4.7.2",
    "react-test-renderer": "^16.2.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.1",
    "stylelint": "^8.4.0",
    "stylelint-config-recommended": "^2.0.1",
    "stylelint-config-styled-components": "^0.1.1",
    "stylelint-order": "^0.8.0",
    "stylelint-processor-styled-components": "^1.2.1",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.9.7",
    "webpack-merge": "^4.1.1"
  },
  "dependencies": {
    "axios": "^0.17.1",
    "gsap": "^1.20.3",
    "immutability-helper": "^2.6.2",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-hot-loader": "^3.1.3",
    "react-router-dom": "^4.2.2",
    "react-transition-group": "^2.2.1",
    "socket.io": "^2.0.4",
    "socket.io-client": "^2.0.4",
    "styled-components": "^3.1.2",
    "styled-reset": "^0.1.3"
  }
}

My .babelrc:

{
  "presets": [
    ["env", {
      "modules": false, // webpack understands the native import syntax and uses it for tree shaking
      "targets": {
        "browsers": ["last 5 versions", "safari >= 7"]
      }
    }],
    "react" // transpile React components to JavaScript
  ],
  "plugins": ["transform-class-properties"],
  "env": {
    "test": {
      "plugins": ["transform-class-properties"],
      "presets": [
        ["env", {
          "targets": {
            "browsers": ["last 5 versions", "safari >= 7"]
          }
        }],
        "react"
      ]
    },
    "dev": {
      "plugins": [
        "react-hot-loader/babel" // enables React code to work with HMR
      ]
    },
    "prod": {
      "plugins": []
    }
  }
}

Let me know if you need any more information! Thanks for the help so far 😄

This error is coming from Electron (Node.js):

Error: Cannot find module 'electron-debug'

Try the Electron supports channels. You're probably having problems with npm or you're loading dependencies incorrectly.

Feel free to continue discussing here. I'm closing the issue as it has nothing to do with the project specifically :)

Fixed it, was actually quite easy (and now I feel stupid).

I had electron-debug installed as a devDependency. When I installed it as a dependency it worked right out of the box!

😊