You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use Ace editor with Svelte but I get a Vite "error when evaluating SSR module" even though I set ssr to false in the components and in the main config. The error says "window not defined" even though I made an "if browser" check in the components that should ensure window is defined. So I'm puzzle as to how to solve this.
kit: {// hydrate the <div id="svelte"> element in src/app.htmltarget: "#svelte",adapter: node(),vite: {ssr: false,},},
Then just run in dev mode and go to the /ace route
Logs
09:51:36 [vite] Error when evaluating SSR module /src/Ace.svelte:
ReferenceError: window is not defined
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21392:21
at _require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:88:37)
at Object.require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:93:26)
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21387:21
at Object.<anonymous> (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21401:15)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
09:51:36 [vite] Error when evaluating SSR module /src/routes/ace.svelte:
ReferenceError: window is not defined
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21392:21
at _require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:88:37)
at Object.require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:93:26)
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21387:21
at Object.<anonymous> (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21401:15)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
window is not defined
ReferenceError: window is not defined
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21392:21
at _require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:88:37)
at Object.require (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:93:26)
at /Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21387:21
at Object.<anonymous> (/Users/fcrz/Code/tuto/code-editor/svelte-ace-minimal/node_modules/ace-builds/src-noconflict/ace.js:21401:15)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
I noticed that when the dev command is running and I'm on the /ace route with the error, if I make a slight code modification like changing the default number of lines and then refresh the page, the component appears. But if I restart the dev command the error comes back.
Why is it evaluating in SSR mode when ssr is false?
Why is window not defined when I setup the editor onMount and check if we are in browser?
The text was updated successfully, but these errors were encountered:
Duplicate of #1650 . This a known limitation of the current ssr setup and a PR is pending to solve that.
You get an error even when doing your work inside onMount because the library you import accesses the window object upon getting imported already. You could try to work around it by importing it dynamically.
Auth : adds "login with signer", and "login with username and password" other functionality to handle pirvate key logins.
i18n : adds `setLang()` functionality to switch language and a number of new keys to default language file.
clientside : adds dedicated module (to be loaded at runtime) for handling `browser only` code in (non svelte component) loaded modules. FIXES :
sveltejs/kit#2814 (comment)
Describe the bug
I'm trying to use Ace editor with Svelte but I get a Vite "error when evaluating SSR module" even though I set ssr to false in the components and in the main config. The error says "window not defined" even though I made an "if browser" check in the components that should ensure window is defined. So I'm puzzle as to how to solve this.
Reproduction
ace-builds
:Ace
component:src/Ace.svelte
ace.svelte
route:src/routes/ace.svelte
/ace
routeLogs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
I noticed that when the dev command is running and I'm on the /ace route with the error, if I make a slight code modification like changing the default number of lines and then refresh the page, the component appears. But if I restart the dev command the error comes back.
Why is it evaluating in SSR mode when ssr is false?
Why is window not defined when I setup the editor onMount and check if we are in browser?
The text was updated successfully, but these errors were encountered: