Giter Site home page Giter Site logo

Comments (3)

secoldPrivate avatar secoldPrivate commented on May 24, 2024 1

Fixed.
For future reference:

I found the code that was causing the problem:

Inside mmy source folder, somewhere in my angular app I was doing:

    ipcRenderer.on('scanner-message', (event, message) => {
      console.log('gotthemessage', message);
      // Do something with the message, like updating the UI
    });

Instead, what you're SUPPOSED to do; is import the provided electronService:

constructor(private electron: ElectronService) {}

and then use THAT thing's ipcRenderer, (it also has fs, and a few other things, i suppose the idea behind this service that wasn't clear to me at the start was that this is a helper service that allows 'safe' access to nodeJs things, without blowing up when running on the browser that doesn't have access to nodeJS).

    this.electron.ipcRenderer.on('scanner-message', (event, message) => {
      console.log('gotthemessage', message);
      // Do something with the message, like updating the UI
    });

I understand now.

Thank you for the project; Very nice.

from angular-electron.

maximegris avatar maximegris commented on May 24, 2024

Hi
Please check providers/electron.service.ts to watch how conditional import of libraries has to be done when using NodeJS / 3rd party libraries in renderer context (i.e. Angular).

from angular-electron.

secoldPrivate avatar secoldPrivate commented on May 24, 2024

@maximegris

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

Why is the error appearing inside of index.js in node_modules?
the 'fs' of getElectronPath:

const fs = require('fs');
const path = require('path');

const pathFile = path.join(__dirname, 'path.txt');

function getElectronPath () {
  let executablePath;
  if (fs.existsSync(pathFile)) {
    executablePath = fs.readFileSync(pathFile, 'utf-8');
  }
  if (process.env.ELECTRON_OVERRIDE_DIST_PATH) {
    return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron');
  }
  if (executablePath) {
    return path.join(__dirname, 'dist', executablePath);
  } else {
    throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again');
  }
}

module.exports = getElectronPath();

I can't see where my application code is importing fs, how can I find it?

The readme says:

NodeJS's one - Uses NodeJS core module (crypto, fs, util...)
I suggest you add this kind of 3rd party library in dependencies of both app/package.json and package.json (root folder) in order to make it work in both Electron's Main process (app folder) and Electron's Renderer process (src folder).

But you can't actually add 'fs' or any of those core modules into package.json.

One possibility is i'm important and using a module that itself is importing fs somewhere inside it; but i can't figure out which one.

from angular-electron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.