electron-store
electron-store copied to clipboard
Uncaught TypeError: path.join is not a function
Hi, I met some problems,Help solve it, thank you this is my project:https://github.com/qypone/xingkong3
dev env: node:14.17.3 electron:^19.0.1 electron-store:^8.0.1 vite:^2.9.9
vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const path = require('path')
// https://vitejs.dev/config/
export default defineConfig({
//base: path.resolve(__dirname, './dist'),
base: "./",
plugins: [vue()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
}
})
main.js
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(ElementPlus).mount('#app')
electron/main.js
const { app, BrowserWindow, Menu, screen } = require('electron')
const path = require('path')
const NODE_ENV = process.env.NODE_ENV
function createWindow() {
const size = screen.getPrimaryDisplay().workAreaSize
const width = parseInt(size.width * 0.9)
const height = parseInt(size.height * 0.9)
const mainWindow = new BrowserWindow({
width: width,
height: height,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false
},
icon: path.join(__dirname, '../public/XingK.ico')
})
mainWindow.loadURL(
NODE_ENV === 'development'
? 'http://localhost:3000'
:`file://${path.join(__dirname, '../dist/index.html')}`
);
if (NODE_ENV === "development") {
mainWindow.webContents.openDevTools()
}
}
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
when i run my project

I had the same problem, not just electron-store, this is a part of my package.json file:
"electron": "16.2.5",
"electron-builder": "23.1.0",
"typescript": "4.6.4",
"vite": "2.9.5",
when create the BrowserWindow, I use this config:
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false,
}
I try to use electron-store, lowdb, electron-localstorage, but I have problems with both.
Uncaught TypeError: path.join is not a function
at node_modules/electron-localstorage/index.js (electron-localstorage.js:76)
at __require (chunk-J43GMYXM.js:11)
at electron-localstorage.js:141

Yes same here, any updates on this issue ?
@qypone @Edge-coordinates, were you able to find any solution for this error ?
bump. anyone able to get this working?
this may help you https://electron-vite.github.io/guide/dependency-pre-bundling.html
same problem.. using const { ipcRenderer } = require("electron"); for example works but gives me an eslint error
Vite's pre-bundle all third-party npm-pkg into Web format, but it doesn't fully work with the Electron Renderer process.For this purpose vite-plugin-electron-renderer provides Pre-Bundling adapted to the Electron Renderer process.
@qypone @Edge-coordinates, were you able to find any solution for this error ?
Vite's pre-bundle all third-party npm-pkg into Web format, but it doesn't fully work with the Electron Renderer process.For this purpose vite-plugin-electron-renderer provides Pre-Bundling adapted to the Electron Renderer process.
Should be a vite problem. Thank to @CYTTP 's help~