vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.43k stars 353 forks source link

"Stumbled upon a Vike bug" with vanilla-extract and `prerender: true` #1791

Closed bard closed 3 months ago

bard commented 3 months ago

Description

5:42:44 PM [vike][Warning] Vite's development server was instantiated while the environment is set to be a production environment by process.env.NODE_ENV === "production" which is contradictory, see https://vike.dev/NODE_ENV
Error: [vike@0.4.182][Bug] You stumbled upon a Vike bug. Go to https://github.com/vikejs/vike/issues/new and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).
    at initGlobalContext (file:///tmp/project/node_modules/.pnpm/vike@0.4.182_react-streaming@0.3.43_react-dom@18.3.1_react@18.3.1__react@18.3.1__vite@5.3.5_@types+node@22.1.0_/node_modules/vike/dist/esm/node/runtime/globalContext.js:90:9)
    at runPrerender (file:///tmp/project/node_modules/.pnpm/vike@0.4.182_react-streaming@0.3.43_react-dom@18.3.1_react@18.3.1__react@18.3.1__vite@5.3.5_@types+node@22.1.0_/node_modules/vike/dist/esm/node/prerender/runPrerender.js:81:11)
    at runPrerenderFromAutoFullBuild (file:///tmp/project/node_modules/.pnpm/vike@0.4.182_react-streaming@0.3.43_react-dom@18.3.1_react@18.3.1__react@18.3.1__vite@5.3.5_@types+node@22.1.0_/node_modules/vike/dist/esm/node/prerender/runPrerender.js:48:9)
    at triggerFullBuild (file:///tmp/project/node_modules/.pnpm/vike@0.4.182_react-streaming@0.3.43_react-dom@18.3.1_react@18.3.1__react@18.3.1__vite@5.3.5_@types+node@22.1.0_/node_modules/vike/dist/esm/node/plugin/plugins/autoFullBuild.js:92:9)
    at Object.handler (file:///tmp/project/node_modules/.pnpm/vike@0.4.182_react-streaming@0.3.43_react-dom@18.3.1_react@18.3.1__react@18.3.1__vite@5.3.5_@types+node@22.1.0_/node_modules/vike/dist/esm/node/plugin/plugins/autoFullBuild.js:31:25)
    at async Promise.all (index 0)
    at PluginDriver.hookParallel (file:///tmp/project/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:19702:9)
    at file:///tmp/project/node_modules/.pnpm/rollup@4.18.0/node_modules/rollup/dist/es/shared/node-entry.js:20699:13

Probably related: https://github.com/vikejs/vike/issues/1592

Only happening on vite build. Based on the warning at the beginning, I tried both NODE_ENV=development vite build and NODE_ENV=production vite build, no difference.

vite.config.ts:

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import vike from "vike/plugin";
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";

export default defineConfig({
  plugins: [vike({ prerender: true }), react({}), vanillaExtractPlugin({})],
});

Removing vanillaExtractPlugin and VE-based styles allows the build to complete. Likewise if I remove prerender: true.

bard commented 3 months ago

Worked around by locking @vanilla-extract/vite-plugin at 4.0.0. The first version that triggers the problem is 4.0.1.

brillout commented 3 months ago

Can you publish a reproduction?

bard commented 3 months ago

@brillout https://github.com/bard/repro-vike-vanilla-css-extract-bug

brillout commented 3 months ago

Fix pre-released in 0.4.183-commit-38f60f1. The build should now pass. Let me know if you stumble upon any other issues.

In case your company is up for it, we're looking for sponsors (#1350). It makes a big difference to us!

bard commented 3 months ago

Confirmed as working. Thanks!