electron-vite / create-electron-vite

Scaffolding Your Electron⚡️Vite Project
MIT License
180 stars 21 forks source link

`Error: vite-plugin-electron-renderer tried to access esbuild, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.` #27

Open nelsonni opened 1 year ago

nelsonni commented 1 year ago

The yarn create electron-vite electron-vite-project command in the README results in a non-runnable Electron application. After installing dependencies through yarn (or yarn install), and attempting to launch the dev mode via yarn dev, I get the following error:

error when starting dev server:
Error: vite-plugin-electron-renderer tried to access esbuild, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: esbuild (via "esbuild/package.json")
Required by: vite-plugin-electron-renderer@npm:0.14.5 (via /Users/nelsonni/Workspace/electron-vite-project/.yarn/cache/vite-plugin-electron-renderer-npm-0.14.5-3e9f36a2d1-50628357bc.zip/node_modules/vite-plugin-electron-renderer/dist/index.mjs)

The full log is included below:

❯ yarn create electron-vite electron-vite-project
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ create-electron-vite@npm:0.4.0 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 1s 55ms
➤ YN0000: Done with warnings in 1s 201ms

✔ Project template: › React

Scaffolding project in /Users/nelsonni/Workspace/electron-vite-project...

Done. Now run:

  cd electron-vite-project
  yarn
  yarn dev

❯ cd electron-vite-project
❯ yarn
➤ YN0000: ┌ Resolution step
➤ YN0032: │ node-addon-api@npm:1.7.2: Implicit dependencies on node-gyp are discouraged
➤ YN0032: │ fsevents@npm:2.3.3: Implicit dependencies on node-gyp are discouraged
➤ YN0000: └ Completed in 5s 248ms
➤ YN0000: ┌ Fetch step
➤ YN0013: │ yallist@npm:4.0.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs-parser@npm:21.1.1 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yargs@npm:17.7.2 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yauzl@npm:2.10.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0013: │ yocto-queue@npm:0.1.0 can't be found in the cache and will be fetched from the remote registry
➤ YN0000: └ Completed in 0s 563ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ electron@npm:26.4.0 must be built because it never has been before or the last one failed
➤ YN0007: │ esbuild@npm:0.18.20 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 1s 940ms
➤ YN0000: Done with warnings in 7s 793ms
❯ yarn dev
error when starting dev server:
Error: vite-plugin-electron-renderer tried to access esbuild, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: esbuild (via "esbuild/package.json")
Required by: vite-plugin-electron-renderer@npm:0.14.5 (via /Users/nelsonni/Workspace/electron-vite-project/.yarn/cache/vite-plugin-electron-renderer-npm-0.14.5-3e9f36a2d1-50628357bc.zip/node_modules/vite-plugin-electron-renderer/dist/index.mjs)

    at makeError (/Users/nelsonni/Workspace/electron-vite-project/.pnp.cjs:13905:34)
    at resolveToUnqualified (/Users/nelsonni/Workspace/electron-vite-project/.pnp.cjs:15582:21)
    at Object.resolveToUnqualified (/Users/nelsonni/Workspace/electron-vite-project/.pnp.cjs:15764:26)
    at resolve$1 (file:///Users/nelsonni/Workspace/electron-vite-project/.pnp.loader.mjs:1977:31)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
nelsonni commented 1 year ago

The npm and pnpm versions do not have this issue, so it appears to be isolated to using yarn.

caoxiemeihao commented 1 year ago

Maybe the following example is better for you. https://github.com/caoxiemeihao/electron-vite-samples/tree/main/serialport-renderer-process