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

Can't import @sveltejs/vite-plugin-svelte into electron app #837

Closed
Sahasrara opened this issue Jan 11, 2024 · 3 comments
Closed

Can't import @sveltejs/vite-plugin-svelte into electron app #837

Sahasrara opened this issue Jan 11, 2024 · 3 comments

Comments

@Sahasrara
Copy link

Describe the bug

Here's my vite.renderer.config.ts file:

import { svelte } from '@sveltejs/vite-plugin-svelte';
import path from 'path';
import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig(async () => ({
    plugins: [svelte()],
    resolve: {
        alias: {
            '@lib': path.resolve(__dirname, './src/lib'),
        },
    },
}));

The app was created with electron forge's vite / typescript template. However, when I go to import this plugin, I get the following error:

An unhandled rejection has occurred inside Forge:
Error: Build failed with 1 error:
node_modules/@electron-forge/plugin-vite/node_modules/esbuild/lib/main.js:1373:27: ERROR: [plugin: externalize-deps] Failed to resolve "@sveltejs/vite-plugin-svelte". This package is ESM only but it was tried to load by `require`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.
at failureErrorWithLog (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1649:15)
    at D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1058:25
    at runOnEndCallbacks (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1484:45)
    at buildResponseToResult (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1056:7)
    at D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1085:16
    at responseCallbacks.<computed> (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:703:9)
    at handleIncomingPacket (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:762:9)
    at Socket.readFromStdout (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
    at Socket.Readable.push (node:internal/streams/readable:375:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Reproduction URL

https://github.com/Sahasrara/vite-plugin-svelte-electron-repro/tree/main/GameScript

Reproduction

Checkout the repo and run npm start

Logs

An unhandled rejection has occurred inside Forge:
Error: Build failed with 1 error:
node_modules/@electron-forge/plugin-vite/node_modules/esbuild/lib/main.js:1373:27: ERROR: [plugin: externalize-deps] Failed to resolve "@sveltejs/vite-plugin-svelte". This package is ESM only but it was tried to load by `require`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.
at failureErrorWithLog (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1649:15)
    at D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1058:25
    at runOnEndCallbacks (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1484:45)
    at buildResponseToResult (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1056:7)
    at D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:1085:16
    at responseCallbacks.<computed> (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:703:9)
    at handleIncomingPacket (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:762:9)
    at Socket.readFromStdout (D:\Work\forge\TMP\GameScript\node_modules\@electron-forge\plugin-vite\node_modules\esbuild\lib\main.js:679:7)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
    at Socket.Readable.push (node:internal/streams/readable:375:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

System Info

PS D:\Work\forge\TMP\GameScript> npx envinfo --system --binaries --browsers --npmPackages "{svelte,svelte-hmr,@sveltejs/*,vite}"
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path C:\Users\emful\AppData\Roaming\npm
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\emful\AppData\Roaming\npm'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in: C:\Users\emful\AppData\Local\npm-cache\_logs\2024-01-11T22_45_02_074Z-debug-0.log
@Sahasrara Sahasrara added bug Something isn't working triage Awaiting triage by a project member labels Jan 11, 2024
@Conduitry
Copy link
Member

As the error indicates, this package is published only as ESM. I don't know how @electron-forge/plugin-vite is attempting to load vite-plugin-svelte, but if it's trying to require() it like the error message indicates, then that's not going to work, and that other plugin will need to do something different.

A quick search on its issue tracker reveals electron/forge#3439 which may be relevant.

@caoxiemeihao
Copy link

This perhaps help you. 👉 electron/forge#3309

@dominikg dominikg added downstream and removed bug Something isn't working triage Awaiting triage by a project member labels Jan 12, 2024
@dominikg
Copy link
Member

This perhaps help you. 👉 electron/forge#3309

as mentioned in that issue, svelte.config.mjs does not work for sveltekit (it does work for vite+svelte)

Using commonjs for svelte projects is highly discouraged, if you want to use vite-plugin-svelte from commonjs, follow the workaround documented here: https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#how-can-i-use-vite-plugin-svelte-from-commonjs

@dominikg dominikg closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants