[PnP] Cannot find the package "electron"
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 641
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 30
Description
### Pre-flight checklist
- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.
### Electron Forge version
7.4.0
### Electron version
30.1.0
### Vite version
5.0.12
### Operating system
Windows 11
### Last known working Electron Forge version
_No response_
### Expected behavior
No error
### Actual behavior
```console
✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies [0.4s]
✔ Running generateAssets hook
The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
✔ [plugin-vite] Launching dev servers for renderer process code [1s]
✔ [plugin-vite] Compiling main process code [2s]
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
vite v5.2.12 building for development...
watching for file changes...
vite v5.2.12 building for development...
watching for file changes...
build started...
build started...
transforming (1) src\preload.ts
transforming (1) src\main.ts
✓ 1 modules transformed.
Generated an empty chunk: "preload".
✓ 1 modules transformed.
rendering chunks (1)...
rendering chunks (1)...
computing gzip size (0)...
computing gzip size (1)...
.vite/build/preload.mjs 0.05 kB │ gzip: 0.07 kB │ map: 0.09 kB
built in 85ms.
computing gzip size (0)...
computing gzip size (1)...
.vite/build/main.js 0.90 kB │ gzip: 0.47 kB │ map: 2.53 kB
built in 88ms.
An unhandled rejection has occurred inside Forge:
Error: Cannot find the package "electron". Perhaps you need to run "yarn install" in "C:\"?
at getElectronPackageJSONPath (C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-utils-npm-7.4.0-881d5c9e73-10c0.zip\node_modules\@electron-forge\core-utils\src\electron-version.ts:69:11)
at async getElectronModulePath (C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-utils-npm-7.4.0-881d5c9e73-10c0.zip\node_modules\@electron-forge\core-utils\src\electron-version.ts:82:27)
at async locateElectronExecutable (C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-npm-7.4.0-4c33fc0cff-10c0.zip\node_modules\@electron-forge\core\src\util\electron-executable.ts:9:50)
at async forgeSpawn (C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-npm-7.4.0-4c33fc0cff-10c0.zip\node_modules\@electron-forge\core\src\api\start.ts:157:28)
at async forgeSpawnWrapper (C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-npm-7.4.0-4c33fc0cff-10c0.zip\node_modules\@electron-forge\core\src\api\start.ts:200:23)
at async C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-core-npm-7.4.0-4c33fc0cff-10c0.zip\node_modules\@electron-forge\core\src\api\start.ts:235:21
at async C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-tracer-npm-7.4.0-9f71f99d40-10c0.zip\node_modules\@electron-forge\tracer\src\index.ts:51:14
at async C:\Users\\AppData\Local\Yarn\Berry\cache\@electron-forge-cli-npm-7.4.0-bdb0634abf-10c0.zip\node_modules\@electron-forge\cli\src\electron-forge-start.ts:61:1
```
### Steps to reproduce
- Clone https://github.com/caoxiemeihao/electron-vite-samples/tree/main/forge-esm-ts (you can use https://download-directory.github.io)
- `yarn set version berry`
- Add to `.yarnrc.yml`
```yaml
nodeLinker: pnp
packageExtensions:
# Ghost dependency https://github.com/electron/windows-installer/issues/516
"electron-winstaller@*":
dependencies:
semver: "*"
```
- `yarn add -D @electron-forge/shared-types @types/node` (add peer dependencies)
- `yarn electron-forge start`
### Additional information
With `nodeLinker: node-modules` (instead of `nodeLinker: pnp`) it works.
The error "Cannot find the package "electron"" imply that `forge.config.cts` file isn't found or is empty.
Related #3209 #3502 #3572 #3582 https://github.com/yarnpkg/berry/issues/1020
Contributor guide
Assessment
This issue has not been assessed yet.