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

Uncaught TypeError: path.join is not a function #229

Open
qypone opened this issue Jun 9, 2022 · 8 comments
Open

Uncaught TypeError: path.join is not a function #229

qypone opened this issue Jun 9, 2022 · 8 comments

Comments

@qypone
Copy link

qypone commented Jun 9, 2022

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

@Edge-coordinates
Copy link

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

@louia
Copy link

louia commented Jun 29, 2023

Yes same here, any updates on this issue ?

@mustafa-kapadia1483
Copy link

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

@fredski02
Copy link

bump. anyone able to get this working?

@captainIT
Copy link

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

@creazy231
Copy link

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

@CYTTP
Copy link

CYTTP commented Feb 21, 2024

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.

@Edge-coordinates
Copy link

Edge-coordinates commented Feb 28, 2024

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

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

8 participants