Giter Site home page Giter Site logo

Comments (4)

caoxiemeihao avatar caoxiemeihao commented on May 13, 2024 2

May be neet remove the following options.

renderer: {},

This options will cause Rollup to build code in cjs format. 👉 Config presets (Opinionated)
After removing this option, Rollup will use the esm format to build the code by default, which can avoid the require in the bundle code.

from electron-vite-react.

Kilian avatar Kilian commented on May 13, 2024 1

Unfortunately, some of Electrons scripts use path and those (specifically, node_modules/electron/index.js) get included into the app.<hash>.js bundle, causing an error because path is not available with node integration turned off.

Edit: I am using nativeImage, which according to the Electron docs can be used in the renderer process (so even with nodeIntegration turned off, as I currently do with webpack) but with Vite, that fails with the "path" error:

Uncaught Error: Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.
    at Object.get (browser-external:path:9:13)
    at node_modules/electron/index.js (index.js:4:23)
    at __require (chunk-CYSXIT7F.js?v=b28474e4:8:50)
    at dep:electron:1:16

Edit2: Seems I can work around this by making nativeImage available in the preload script and using it from there.

Bottom line: It would be nice if multiple entry points also worked with the electron-vite-renderer module.

from electron-vite-react.

caoxiemeihao avatar caoxiemeihao commented on May 13, 2024

In fact, if nodeIntegration is not enabled, even the require function cannot be used, although we can use the following to avoid Vite Pre-Bundling node_modules/electron/index.js, but in the where the require function is not available Down. We still can't use any exported members of electron.

// e.g. renderer.js

const { nativeTheme } = require('electron')
// Uncaught ReferenceError: require is not defined

from electron-vite-react.

caoxiemeihao avatar caoxiemeihao commented on May 13, 2024

Now [email protected] is based on the vite-electron-plugin, This is broke!

from electron-vite-react.

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.