oliverschwendener / electron-fluent-ui

Template for developing Electron applications using TypeScript and Fluent UI React components
MIT License
52 stars 11 forks source link

Can't Import any component from Electron #7

Closed ekottifiok closed 1 year ago

ekottifiok commented 1 year ago

When I import { desktopCapturer } from "electron"; and use it like this: desktopCapturer.getSources({ types: ['window', 'screen'] }) Uncaught ReferenceError: __dirname is not defined

oliverschwendener commented 1 year ago

Did you try this in the main or renderer package?

ekottifiok commented 1 year ago

Renderer

ekottifiok commented 1 year ago

Does it work on the main? Would try

oliverschwendener commented 1 year ago

If you want to do this in the renderer you have to enable the node integration for the browser window. This is not recommended for security reasons but if you want to try it out, set nodeIntegration: true when creating the browser window:

packages/main/src/index.ts

const createBrowserWindow = (): BrowserWindow => {
    return new BrowserWindow({
        autoHideMenuBar: true,
        webPreferences: {
            nodeIntegration: true,
            preload: join(__dirname, "..", "..", "preload", "dist", "index.cjs"),
        },
    });
};
ekottifiok commented 1 year ago

it's an electron error this is the error screenshot https://drive.google.com/file/d/1IxB-evwY3Fn9RWeq8bFKdJxm5sCxvnlF/view?usp=share_link

oliverschwendener commented 1 year ago

Then I guess we can close this?

ekottifiok commented 1 year ago

okay thanks for your speedy reply to the issue