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

Cannot able to find module 'electron-log' #91

Closed
SivaThiyagarajan opened this issue Aug 9, 2018 · 25 comments
Closed

Cannot able to find module 'electron-log' #91

SivaThiyagarajan opened this issue Aug 9, 2018 · 25 comments

Comments

@SivaThiyagarajan
Copy link

untitled

@SivaThiyagarajan
Copy link
Author

I have checked Dependencies in Package.json, It was there but still i cant able to find the issue.

Thanks in Advance.

@megahertz
Copy link
Owner

How do you import the package? Do you use webpack?

@SivaThiyagarajan
Copy link
Author

I had installed through NPM

@megahertz
Copy link
Owner

Please provide more details

@SivaThiyagarajan
Copy link
Author

Acctually its a Angular web application , i just used electron to Convert it as a Windows Application, Then I am Working to Implement Auto Updater, then i build the App when I tried to Open the app , i am getting the Above mentioned error.

@megahertz
Copy link
Owner

There are a lot of reasons why the module may be installed incorrectly. I need to see package.json and webpack config to find a reason.

@SivaThiyagarajan
Copy link
Author

const { app, BrowserWindow, Menu, protocol, ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const log = require('electron-log');
const autoUpdater = require("electron-updater");

// 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;

const createWindow = () => {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
icon: path.join(__dirname, 'favicon.ico'),
});

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

// 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();
}
});

// const updater = require('electron-simple-updater');
// updater.init('D:/Update/testone/resources/app/updates.json');

//-------------------------------------------------------------------
// Logging
//
// THIS SECTION IS NOT REQUIRED
//
// This logging setup is not required for auto-updates to work,
// but it sure makes debugging easier :)
//-------------------------------------------------------------------
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
log.info('App starting...');

//-------------------------------------------------------------------
// Define the menu
//
// THIS SECTION IS NOT REQUIRED
//-------------------------------------------------------------------
let template = []
if (process.platform === 'darwin') {
// OS X
const name = app.getName();
template.unshift({
label: name,
submenu: [
{
label: 'About ' + name,
role: 'about'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click() { app.quit(); }
},
]
})
}

//-------------------------------------------------------------------
// Open a window that displays the version
//
// THIS SECTION IS NOT REQUIRED
//
// This isn't required for auto-updates to work, but it's easier
// for the app to show a window than to have to click "About" to see
// that updates are working.
//-------------------------------------------------------------------

function sendStatusToWindow(text) {
log.info(text);
win.webContents.send('message', text);
}
function createDefaultWindow() {
win = new BrowserWindow();
win.webContents.openDevTools();
win.on('closed', () => {
win = null;
});
win.loadURL(file://${__dirname}/version.html#v${app.getVersion()});
return win;
}
autoUpdater.on('checking-for-update', () => {
sendStatusToWindow('Checking for update...');
})
autoUpdater.on('update-available', (ev, info) => {
sendStatusToWindow('Update available.');
})
autoUpdater.on('update-not-available', (ev, info) => {
sendStatusToWindow('Update not available.');
})
autoUpdater.on('error', (ev, err) => {
sendStatusToWindow('Error in auto-updater.');
})
autoUpdater.on('download-progress', (ev, progressObj) => {
sendStatusToWindow('Download progress...');
})
autoUpdater.on('update-downloaded', (ev, info) => {
sendStatusToWindow('Update downloaded; will install in 5 seconds');
});
app.on('ready', function() {
// Create the Menu
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

createDefaultWindow();
});
app.on('window-all-closed', () => {
app.quit();
});

//-------------------------------------------------------------------
// Auto updates
//
// For details about these events, see the Wiki:
// https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events
//
// The app doesn't need to listen to any events except update-downloaded
//
// Uncomment any of the below events to listen for them. Also,
// look in the previous section to see them being used.
//-------------------------------------------------------------------
// autoUpdater.on('checking-for-update', () => {
// })
// autoUpdater.on('update-available', (ev, info) => {
// })
// autoUpdater.on('update-not-available', (ev, info) => {
// })
// autoUpdater.on('error', (ev, err) => {
// })
// autoUpdater.on('download-progress', (ev, progressObj) => {
// })
autoUpdater.on('update-downloaded', (ev, info) => {
// Wait 5 seconds, then quit and install
// In your application, you don't need to wait 5 seconds.
// You could call autoUpdater.quitAndInstall(); immediately
setTimeout(function() {
autoUpdater.quitAndInstall();
}, 5000)
})

app.on('ready', function() {
autoUpdater.checkForUpdates();
});

@SivaThiyagarajan
Copy link
Author

SivaThiyagarajan commented Aug 9, 2018

The Above Code is from Main Process File..

@SivaThiyagarajan
Copy link
Author

{
"name": "testone",
"productName": "testone",
"version": "0.0.0",
"description": "testone",
"main": "electron.prod.js",
"license": "MIT",
"author": {
"name": "siva",
"url": "http://sss94.com"
},
"devDependencies": {
"electron": "^2.0.6",
"electron-builder": "^20.27.1",
"http-server": "^0.9.0",
"electron-log": "^2.2.16",
"electron-updater": "^3.1.1",
"electron-simple-updater": "^1.2.3"
},
"dependencies": {
"electron": "^2.0.6",
"electron-builder": "^20.27.1",
"http-server": "^0.9.0",
"electron-log": "^2.2.16",
"electron-updater": "^3.1.1",
"electron-simple-updater": "^1.2.3"
},
"build": {
"publish": [
{
"provider": "generic",
"url": "D:/Update/testone/"
}
],
"appId": "com.testone.example",
"mac": {
"category": "your.app.category.type",
"target": [
"zip",
"dmg"
]
},
"nsis": {
"perMachine": true
}
}
}

This is my Package.Json file

@megahertz
Copy link
Owner

It seems ok. What's your build script?

@SivaThiyagarajan
Copy link
Author

Build Script? tell me exactly where i need to get that

@megahertz
Copy link
Owner

How do you build the app?

@SivaThiyagarajan
Copy link
Author

SivaThiyagarajan commented Aug 9, 2018

"scripts": {
    "ng": "ng",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "start": "concurrently \"ng serve\" \"npm run electron\"",
    "electron": "electron ./src/electron.dev",
    "package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite ",
    "setup": "electron-installer-windows --src packages/testone-0.0.0-win32-ia32/ --dest dist/installers/"
  }

@megahertz
Copy link
Owner

electron-packager can skip modules from devDependencies. So try to remove electron-log from package.json:devDependencies section.

@SivaThiyagarajan
Copy link
Author

SivaThiyagarajan commented Aug 9, 2018

need to be removed before building the app?

@megahertz
Copy link
Owner

Just remove it forever. I recommend you to keep only electron, electron-builder and may be http-server
inside devDependencies.

@SivaThiyagarajan
Copy link
Author

I just removed from devDependencies and I build the app, Same issue occurs

@megahertz
Copy link
Owner

It seems that your problem is related to PKief/angular-cli-electron#5

I don't know exactly how to fix it because I don't know Angular 2+ and what it exactly generates inside dist folder. I can assume, that there is dist/package.json which doesn't contains modules from the main package.json. So you can try to fix build script (package:win) to copy the /package.json (or dependency part of it) to /dist/package.json before calling electron-packager

@megahertz
Copy link
Owner

Try v3.0.0-beta2. Feel free to reopen if the problem isn't fixed.

@AdditionAddict
Copy link

Moved electron-log to dependancies rather than devDependancies worked for me. Electron includes this module when building exe app

@yousef312
Copy link

I am having the same error guys, I deleted the electron-log devDependencies yet the problem occurs again

@AmFanyuxi
Copy link

Is there anyone resolve the error ?

@megahertz
Copy link
Owner

There are a lot of reasons why the module couldn't be resolved. In most cases it's a wrong bundler configuration.

@robido
Copy link

robido commented Apr 23, 2021

I have the same error in an Electron Vue app. The same problem happens with the package electron-fetch, so maybe it is because the package name starts with "electron-" and is exlcuded by webpack somehow.

The changes in this commit show a minimal change triggering this error:
oliverfindl/electron-vue-boilerplate#6

@megahertz
Copy link
Owner

@robido the electron-vue-bolierplate contains "!node_modules${/*}" in files config of electron builder and externals: [ nodeExternals() ],` in webpack config, I think that's the reason.

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

6 participants