question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with reduxtool kit and adapter-static to build SSG

See original GitHub issue

Describe 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:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dominikgcommented, Oct 12, 2022

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

3reactions
dummdidummcommented, Oct 12, 2022

Add ssr: { noExternal: ["@reduxjs/toolkit"] }, to your vite.config.ts and middleware: [] to your configureStore store call and it should work. @bluwy @dominikg is it expected to put this to noExternal? 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering - Redux Toolkit
In getStaticProps or getServerSideProps : Pre-fetch all queries via the initiate actions, e.g. store.dispatch(api.endpoints.getPokemonByName.
Read more >
How to use Redux toolkit dispatch in Next.js SSG or SSR?
I'm confused a long time to fix my issues on the use Hook like useDispatch in getStaticProps or getServerSideProps . I'm using redux-toolkit...
Read more >
How to Create Pages in Next.js with Static & Dynamic Data
We'll look at how we can use the Next.js data fetching APIs to create both static and dynamic pages. What's Inside.
Read more >
Static Site Generation and Server-Side Rendering Using Next.js
We will also use Redux to create a comment form that will be hydrated the ... Static site generation (SSG) involves generating HTML...
Read more >
Best Practices for Testing a React/Redux Toolkit App - XTIVIA
I would classify code formatting, linting (including complexity analysis), and type-checking as forms of static testing. 2. Build a Minimum ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found