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

__dirname is not defined #269

Closed
captainIT opened this issue Jan 8, 2024 · 1 comment
Closed

__dirname is not defined #269

captainIT opened this issue Jan 8, 2024 · 1 comment

Comments

@captainIT
Copy link

captainIT commented Jan 8, 2024

when use electron-forge
Follow these steps https://www.electronforge.io/templates/typescript-+-webpack-template

then I add following codes to main.ts

const ElectronStore = require('electron-store');
ElectronStore.initRenderer();

after run start, throw error
Uncaught ReferenceError: __dirname is not defined

@captainIT
Copy link
Author

I solved the problem by a third party plugin vite-plugin-electron-renderer

import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'

export default {
  plugins: [
    electron({
      entry: 'electron/main.ts',
    }),
    renderer({
      resolve: {
        // JavaScript cjs lib
        'electron-store': { type: 'cjs' },
      },
    }),
  ],
}

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

1 participant