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

electron-store 10 esm and renderer error #91

Open
HugoGresse opened this issue Dec 16, 2024 · 1 comment
Open

electron-store 10 esm and renderer error #91

HugoGresse opened this issue Dec 16, 2024 · 1 comment

Comments

@HugoGresse
Copy link

HugoGresse commented Dec 16, 2024

Hi wonderful team making the new electron start sooooo easy!

I've started a new project last week, and when importing 'electron-store' in the renderer, the following issue happen.

'electron-store' v10 is now pure ESM, which why adding 'electron-store': { type: 'cjs' }, did change the error but did not solve it (neither 'type: esm', : require is not defined )

It seems there were already fixes for electron-store ESM v10 but all the examples and docs are for the CJS v8 package and the default config changes don't seems to work for me.

Uncaught Error: Dynamic require of "process" is not supported
    at chunk-UN725CXD.js?v=f7b7e0dc:15:9
    at electron-store.js?v=f7b7e0dc:14821:11


--- electron-store.js 
// node_modules/.vite-electron-renderer/process.mjs
var avoid_parse_require = __require;
var _M_ = avoid_parse_require("process");

---  chunk-UN725CXD.js
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
  if (typeof require !== "undefined") return require.apply(this, arguments);
  throw Error('Dynamic require of "' + x + '" is not supported');
});

Related lib:

    "electron": "^30.0.1",
    "electron-builder": "^24.13.3",
    "electron-rebuild": "^3.2.9",
    "typescript": "^5.2.2",
    "vite": "^5.1.6",
    "vite-plugin-electron": "^0.28.6",
    "vite-plugin-electron-renderer": "^0.14.5"
    "better-sqlite3": "^11.7.0",
    "electron-store": "^10.0.0",

vite.config.js

import { defineConfig } from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [
    react(),
    electron({
      main: {
        entry: 'electron/main.ts',
        vite: {
          build: {
            rollupOptions: {
              external: [
                'better-sqlite3'
              ],
            },
          }
        },
      },
      preload: {
        input: path.join(__dirname, 'electron/preload.ts'),
      },
      renderer: process.env.NODE_ENV === 'test'
        // https://github.com/electron-vite/vite-plugin-electron-renderer/issues/78#issuecomment-2053600808
        ? undefined
        : {},
    }),
  ],
})

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

2 participants