@storyblok/astro
This is an updated minimal reproduction for storyblok/monoblok#547. The issue was fixed in storyblok/monoblok#551, but the same build failure is reproducible again with @storyblok/astro@10.0.0.
The reproduction uses Astro components registered through the @storyblok/astro integration. One registered component renders another local component, and that second component imports StoryblokComponent so nested Storyblok blocks can be rendered. With this dependency shape, astro build fails during prerendering with a TDZ ReferenceError.
Current reproduction dependencies:
@storyblok/astro@10.0.0
astro@6.4.8-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Observe that the build fails while rendering
/.
The MRE keeps the component graph minimal:
src/pages/index.astro -> src/storyblok/Card.astro
src/storyblok/Card.astro -> src/storyblok/Richtext.astro
src/storyblok/Richtext.astro -> @storyblok/astro/StoryblokComponent.astro
Both local Storyblok components are registered in astro.config.ts:
storyblok({
accessToken: "dummy",
components: {
card: "storyblok/Card",
text: "storyblok/Richtext",
},
})https://stackblitz.com/github/adamchal/storyblok-tdz?startScript=build
The project should build successfully.
This component shape is expected in CMS-driven Astro projects: a Storyblok component can render rich text, and rich text can render nested Storyblok blocks through StoryblokComponent.
The build fails during prerendering with:
ReferenceError: Cannot access '$$Card' before initializationSystem:
OS: macOS 15.7.7
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Memory: 35.02 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 26.3.0 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.9.8 - /usr/local/bin/npm
pnpm: 10.30.3 - /usr/local/bin/pnpm
bun: 0.1.13 - /Users/adam/.bun/bin/bun
Deno: 2.8.3 - /usr/local/bin/deno
Browsers:
Chrome: 149.0.7827.155
Firefox: 148.0
Safari: 26.5
Safari Technology Preview: 26.0
npmPackages:
@storyblok/astro: ^10.0.0 => 10.0.0
astro: ^6.4.8 => 6.4.8> build
> astro build
12:44:39 [types] Generated 19ms
12:44:39 [build] output: "static"
12:44:39 [build] mode: "static"
12:44:39 [build] directory: /private/tmp/storyblok-tdz/dist/
12:44:39 [build] Collecting build info...
12:44:39 [build] Completed in 35ms.
12:44:39 [build] Building static entrypoints...
12:44:40 [vite] built in 667ms
12:44:40 [vite] built in 37ms
12:44:40 [build] Rearranging server assets...
generating static routes
12:44:40 ├─ /index.html
12:44:40 [ERROR] ReferenceError: Cannot access '$$Card' before initialization
at file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/index_LZ5puxTa.mjs:761:29
at ModuleJob.run (node:internal/modules/esm/module_job:439:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:646:26)
at async BuildPipeline.getModuleForRoute (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9920:14)
at async BuildPipeline.getComponentByRoute (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9892:20)
at async FetchState.getProps (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:7562:17)
at async AstroMiddleware.handle (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:6569:5)
at async AstroHandler.render (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9033:20)
at async BuildApp.render (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9495:18)
at async renderPath (file:///private/tmp/storyblok-tdz/node_modules/astro/dist/core/build/generate.js:260:16)
12:44:40 [ERROR] [build] Caught error rendering /: ReferenceError: Cannot access '$$Card' before initialization
Cannot access '$$Card' before initialization
Stack trace:
at file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/index_LZ5puxTa.mjs:761:29
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:646:26)
at async BuildPipeline.getComponentByRoute (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9892:20)
at async AstroMiddleware.handle (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:6569:5)
at async BuildApp.render (file:///private/tmp/storyblok-tdz/dist/.prerender/chunks/prerender_CsCAJBUi.mjs:9495:18)