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

[PnP] Cannot find the package "electron" #3611

Open
3 tasks done
rtritto opened this issue May 29, 2024 · 5 comments
Open
3 tasks done

[PnP] Cannot find the package "electron" #3611

rtritto opened this issue May 29, 2024 · 5 comments

Comments

@rtritto
Copy link

rtritto commented May 29, 2024

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • 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

✔ 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:\<PROJECT_PATH>"?
at getElectronPackageJSONPath (C:\Users\<USER>\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\<USER>\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\<USER>\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\<USER>\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\<USER>\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\<USER>\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\<USER>\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\<USER>\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

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 yarnpkg/berry#1020

@rtritto
Copy link
Author

rtritto commented May 30, 2024

@rtritto
Copy link
Author

rtritto commented May 30, 2024

Some open points:

  1. maybe this issue will be fixed with feat(core): support ESM Forge module loading #3582 because forge.config.ts should work instead of forge.config.cts
  2. should the PnP loader be added to ts-node (example: yarn node --loader ts-node/esm --loader ./.pnp.loader.mjs ./src/main.ts)?
  3. can the ts-node use be replaced with tsx or tslib?
@rtritto
Copy link
Author

rtritto commented Jun 2, 2024

@rtritto
Copy link
Author

rtritto commented Jun 8, 2024

@merceyz what is the correct resolution for yarn berry / PnP?

async function determineNodeModulesPath(dir: string, packageName: string): Promise<string | undefined> {
const nodeModulesPath: string | undefined = path.join(dir, 'node_modules', packageName);
if (await fs.pathExists(nodeModulesPath)) {
return nodeModulesPath;
}
return findAncestorNodeModulesPath(dir, packageName);
}

I opened discussions: #6323 #8185

@merceyz
Copy link

merceyz commented Jun 8, 2024

Use require.resolve to locate dependencies regardless of whether PnP is used or not.

require.resolve(`${packageName}/package.json`, { paths: [dir] });
@rtritto rtritto changed the title [Typescript + ESM + PnP] forge.config.cts not recognized with PnP (Plug'n'Play) Jun 9, 2024
@rtritto rtritto mentioned this issue Jun 20, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants