Skip to content

TypeError: Cannot read properties of undefined (reading 'source') #36

@Delta-official

Description

@Delta-official

Running pnpm vite build with the following config:

import { globSync } from "glob";
import { defineConfig } from "vite";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import path from "path";
import preact from "@preact/preset-vite";

const __dirname = dirname(fileURLToPath(import.meta.url));

export default defineConfig({
    plugins: [
        preact({
            prerender: {
                enabled: true
            }
        }),
    ],
    build: {
        rolldownOptions: {
            input: Object.fromEntries(
                globSync("src/**/index.html").map((file) => [
                    path.basename(path.dirname(file.slice(0, file.length - path.extname(file).length))),
                    resolve(__dirname, file),
                ]),
            ),
        },
    },
})

and project structure:

├── package.json
├── pnpm-lock.yaml
├── src
│   └── dashboard
│       ├── index.html
│       └── main.tsx
├── tsconfig.json
└── vite.config.ts

results in the following error:

vite v8.0.8 building client environment for production...
✓ 7 modules transformed.
✗ Build failed in 69ms
error during build:
Build failed with 1 error:

[plugin vite-prerender-plugin]
TypeError: Cannot read properties of undefined (reading 'source')
    at PluginContextImpl.generateBundle (file:///<snip>/front-end/node_modules/.pnpm/vite-prerender-plugin@0.5.13_vite@8.0.8/node_modules/vite-prerender-plugin/src/plugins/prerender-plugin.js:292:67)
    at PluginContextImpl.handler (file:///<snip>/front-end/node_modules/.pnpm/vite@8.0.8/node_modules/vite/dist/node/chunks/node.js:33214:13)
    at plugin (file:///<snip>/front-end/node_modules/.pnpm/rolldown@1.0.0-rc.15/node_modules/rolldown/dist/shared/bindingify-input-options-DYpBf1OG.mjs:1360:18)
    at plugin.<computed> (file:///<snip>/front-end/node_modules/.pnpm/rolldown@1.0.0-rc.15/node_modules/rolldown/dist/shared/bindingify-input-options-DYpBf1OG.mjs:1636:18)
    at aggregateBindingErrorsIntoJsError (file:///<snip>/front-end/node_modules/.pnpm/rolldown@1.0.0-rc.15/node_modules/rolldown/dist/shared/error-w0u7biK-.mjs:48:18)
    at unwrapBindingResult (file:///<snip>/front-end/node_modules/.pnpm/rolldown@1.0.0-rc.15/node_modules/rolldown/dist/shared/error-w0u7biK-.mjs:18:128)
    at #build (file:///<snip>/front-end/node_modules/.pnpm/rolldown@1.0.0-rc.15/node_modules/rolldown/dist/shared/rolldown-build-DtGk-m96.mjs:3313:34)
    at async buildEnvironment (file:///<snip>/front-end/node_modules/.pnpm/vite@8.0.8/node_modules/vite/dist/node/chunks/node.js:32954:64)
    at async Object.build (file:///<snip>/front-end/node_modules/.pnpm/vite@8.0.8/node_modules/vite/dist/node/chunks/node.js:33376:19)
    at async Object.buildApp (file:///<snip>/front-end/node_modules/.pnpm/vite@8.0.8/node_modules/vite/dist/node/chunks/node.js:33373:153)
    at async CAC.<anonymous> (file:///<snip>/front-end/node_modules/.pnpm/vite@8.0.8/node_modules/vite/dist/node/cli.js:778:3) {
  errors: [Getter/Setter]

Packages:

    "dependencies": {
        "preact": "10.29.1",
        "preact-render-to-string": "6.6.7"
    },
    "devDependencies": {
        "@preact/preset-vite": "^2.10.5",
        "glob": "^13.0.6",
        "vite": "8.0.8"
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions