electron-store icon indicating copy to clipboard operation
electron-store copied to clipboard

Uncaught TypeError: path.join is not a function

Open qypone opened this issue 3 years ago • 8 comments

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 image

qypone avatar Jun 09 '22 15:06 qypone

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

image

Edge-coordinates avatar Jan 31 '23 09:01 Edge-coordinates

Yes same here, any updates on this issue ?

louia avatar Jun 29 '23 16:06 louia

@qypone @Edge-coordinates, were you able to find any solution for this error ?

mustafa-kapadia1483 avatar Aug 30 '23 08:08 mustafa-kapadia1483

bump. anyone able to get this working?

fredski02 avatar Dec 19 '23 22:12 fredski02

this may help you https://electron-vite.github.io/guide/dependency-pre-bundling.html

captainIT avatar Jan 08 '24 06:01 captainIT

same problem.. using const { ipcRenderer } = require("electron"); for example works but gives me an eslint error

creazy231 avatar Jan 16 '24 14:01 creazy231

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.

CYTTP avatar Feb 21 '24 13:02 CYTTP

@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~

Edge-coordinates avatar Feb 28 '24 13:02 Edge-coordinates