electron/remote

Module not found: Error: Can't resolve 'fs'

TheColorRed opened this issue · 7 comments

When I add the @electron/remote module, I get an error in node_modules\electron\index.js giving the following error:

./node_modules/electron/index.js:1:11-24 - Error: Module not found: Error: Can't resolve 'fs' in 'C:...\node_modules\electron'

The app also does not start up. This is what I did in my main app:

const { app, BrowserWindow, ipcMain } = require('electron')
require('@electron/remote/main').initialize()

let win
function createWindow() {
  win = new BrowserWindow({
    width: 1024,
    height: 650,
    minWidth: 1024,
    minHeight: 650,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
      contextIsolation: false
    }
  })
  require('@electron/remote/main').enable(win.webContents)
}
app.on('ready', createWindow)

I have also tried

const { app, BrowserWindow, ipcMain, webContents } = require('electron')
require('@electron/remote/main').initialize()
require('@electron/remote/main').enable(webContents)

Then in my Angular app, I have the following:

import { Injectable } from '@angular/core'
const remote = require('@electron/remote')

@Injectable({ providedIn: 'root' })
export class SettingsService {
  constructor() {
    console.log('remote', remote.require('fs'))
  }
}

I tried to write it like this,and it worked
const remote = window.require('@electron/remote')

我试着这样写,它奏效了 const remote = window.require('@electron/remote')

thanks

what's the explanation for this?
Why do we have to use window.require('@electron/remote') rather than require('@electron/remote')?

I tried to write it like this,and it worked const remote = window.require('@electron/remote')

i got this error TypeError: window.require is not a function

I moved every transaction to ipc, Seems that Electron 29 changed even more in their security policy (which is OK, just nice to know)

Thanks for reaching out!

The issues tracker is used for feature requests and bug reports, so you will probably have better luck with this question at one of the links at the project's Community page -- in particular, be sure to give the Electron Discord server a try.

I hope this helps!

@miniak thank you for the reply... but I was not requesting a feature. I added my solution due to changes in electron. I felt like this might be helpful to others that notice this "BUG".

The question is if this mechanism is generally deprecated in newer electron versions.

And again to be clear. Not asking, rather trying to help others understand why this might happen in their app.


EDIT: Just saw that you closed this issue. Yes I agree.