Issue with reduxtool kit and adapter-static to build SSG
See original GitHub issueDescribe the bug
it works on SSR and CSR, but SSG doesn’t, when I config to build SSG, it logs errors about reduxtoolkit
TypeError: configureStore is not a function at file:///…/my-app/.svelte-kit/output/server/entries/pages/_layout.svelte.js:41:15 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:533:24) at async Module.component (file:///my-app/.svelte-kit/output/server/nodes/0.js:4:39) at async Promise.all (index 0) at async render_response (file://…/my-app/.svelte-kit/output/server/index.js:1218:19) at async render_page (file://…/my-app/.svelte-kit/output/server/index.js:1676:12) at async resolve (file://…/my-app/.svelte-kit/output/server/index.js:1981:22) at async respond (file://…/my-app/.svelte-kit/output/server/index.js:2019:22)
[vite-plugin-svelte-kit] Prerendering failed with code 1 error during build: Error: Prerendering failed with code 1 at ChildProcess.<anonymous> (file:///…/my-app/node_modules/@sveltejs/kit/src/exports/vite/index.js:438:15) at ChildProcess.emit (node:events:513:28) at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
Process finished with exit code 1
Reproduction
https://github.com/Linh2196/sveltekit-test
Logs
TypeError: configureStore is not a function
at file:///.../my-app/.svelte-kit/output/server/entries/pages/_layout.svelte.js:41:15
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:533:24)
at async Module.component (file:///my-app/.svelte-kit/output/server/nodes/0.js:4:39)
at async Promise.all (index 0)
at async render_response (file://.../my-app/.svelte-kit/output/server/index.js:1218:19)
at async render_page (file://.../my-app/.svelte-kit/output/server/index.js:1676:12)
at async resolve (file://.../my-app/.svelte-kit/output/server/index.js:1981:22)
at async respond (file://.../my-app/.svelte-kit/output/server/index.js:2019:22)
[vite-plugin-svelte-kit] Prerendering failed with code 1
error during build:
Error: Prerendering failed with code 1
at ChildProcess.<anonymous> (file:///.../my-app/node_modules/@sveltejs/kit/src/exports/vite/index.js:438:15)
at ChildProcess.emit (node:events:513:28)
at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
Process finished with exit code 1
System Info
macOS Monterey 12.6
Chip Apple M1 Pro
Mem 32GB
Severity
blocking an upgrade
Additional Information
In older sveltekit, (1.0.0-next.168) it 's running stable. But I want to upgrade to latest version
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
https://publint.bjornlu.com/@reduxjs/toolkit@1.8.6 looks like they have a cjs package but provide a module field? on top of that it use the infamous .esm.js extension instead of .mjs
Looks like suboptimal packaging on their end to me and noExternal being a workaround. The solution would be redux toolkit offering a proper esm package
Add
ssr: { noExternal: ["@reduxjs/toolkit"] },
to yourvite.config.ts
andmiddleware: []
to yourconfigureStore
store call and it should work. @bluwy @dominikg is it expected to put this tonoExternal
? It looks like Vite is loading the CJS version if not done, and that somehow fails with all import methods that should work - want to make sure this is not a Vite bug.