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

App fails to build if I use ipcRenderer #401

Closed
0xPT opened this issue Sep 17, 2023 · 6 comments
Closed

App fails to build if I use ipcRenderer #401

0xPT opened this issue Sep 17, 2023 · 6 comments

Comments

@0xPT
Copy link

0xPT commented Sep 17, 2023

As seen in the README and in the ipc-communication example, when I include this code in the file it doesn't work and gives me this error.

const ipcRenderer = electron?.ipcRenderer || false;
      
useEffect(() => {
    if (ipcRenderer) {
      ipcRenderer.on("channel", (event, data) => {
        setData(data);
      });
      return () => {
        ipcRenderer.removeAllListeners("channel");
      };
    }
 }, []);

Error occurred prerendering page "/login". Read more: https://nextjs.org/docs/messages/prerender-error Error: Electron failed to install correctly, please delete node_modules/electron and try installing again

@AbdeenM
Copy link

AbdeenM commented Sep 27, 2023

@0xPT have you managed to find a solution?

@0xPT
Copy link
Author

0xPT commented Sep 28, 2023

@AbdeenM

I did figure out a solution for this.

  useEffect(() => {
    const ipcRenderer = require("electron").ipcRenderer || false;

    if (ipcRenderer) {
      ipcRenderer.on("authorize", (event, data) => {
        setSession(data);
      });
      return () => {
        ipcRenderer.removeAllListeners("authorize");
      };
    }
  }, []);

@AbdeenM
Copy link

AbdeenM commented Sep 29, 2023

Still running into the same problem, did you come across this?

../../../node_modules/electron/index.js:1:0
Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./pages/index.tsx

@0xPT
Copy link
Author

0xPT commented Sep 29, 2023

Still running into the same problem, did you come across this?


../../../node_modules/electron/index.js:1:0

Module not found: Can't resolve 'fs'



https://nextjs.org/docs/messages/module-not-found



Import trace for requested module:

./pages/index.tsx

Could you provide the code where this is occurring?

@adammenges
Copy link

I'm running into the same thing @0xPT & @AbdeenM

home.tsx

import React from "react";
import Head from "next/head";
import Link from "next/link";
import Image from "next/image";
import ipcRenderer from "electron";
import { useEffect } from 'react';


function sendMessage() {
  console.log("sending message");
  useEffect(() => {
    const ipcRenderer = require("electron").ipcRenderer || false;
  
    if (ipcRenderer) {
      ipcRenderer.send("message", "Hello");
    }
  }, []);
}

export default function HomePage() {
  return (
    <React.Fragment>
      <Head>
        <title>Adam's Dumb App</title>
      </Head>
      <div className="grid grid-col-1 text-2xl w-full text-center">
        <div onClick={sendMessage}> click meeeee </div>
      </div>
      <div className="mt-1 w-full flex-wrap flex justify-center">
        <Link href="/next">Go to next page</Link>
      </div>
    </React.Fragment>
  );
}

CleanShot 2024-05-08 at 15 32 58@2x
I'm not importing fs. Just ran into this and still debugging.

@adammenges
Copy link

got it: #415

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