try {
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
import.meta.resolve('electron-squirrel-startup/package.json')
app.quit()
} catch (error) {
// Ignore
console.log('Ignore error: ', error)
}
Console output:
Ignore error: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'electron-squirrel-startup' imported from C:\template-electron-vite\.vite\build\main.js
at packageResolve (node:internal/modules/esm/resolve:861:9)
at moduleResolve (node:internal/modules/esm/resolve:934:18)
at defaultResolve (node:internal/modules/esm/resolve:1164:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:365:17)
at Object.resolve (node:internal/modules/esm/initialize_import_meta:30:25)
at file:///C:/template-electron-vite/.vite/build/main.js:6:15
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadApplicationPackage (file:///C:/template-electron-vite/.yarn/unplugged/electron-npm-31.0.0-df97707901/node_modules/electron/dist/resources/default_app.asar/main.js:129:9) {
code: 'ERR_MODULE_NOT_FOUND'
}
I did a try with other dependencies such as react and solid-js.
Stack
Electron Forge + Electron + Vite + ESM + Plug'n'Play (PnP) + Typescript
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
[X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
With ESM, the
electron-squirrel-startup dependency
can't be found if it's in dependencies (it works if I move it into devDependencies):require.resolve
(Node < 20.6.0) example;src/main.ts
file:Console output:
import.meta.resolve
(Node.js >= 20.6.0) example;src/main.ts
file:Console output:
I did a try with other dependencies such as react and solid-js.
Stack
Electron Forge + Electron + Vite + ESM + Plug'n'Play (PnP) + Typescript
Reproduction
https://github.com/rtritto/template-electron-vite
Steps to reproduce
git clone https://github.com/rtritto/template-electron-vite.git
cd template-electron-vite
yarn
yarn start
System Info
Used Package Manager
yarn
Logs
No response
Validations