vite-ssg
vite-ssg copied to clipboard
Build fails with error: TypeError: Invalid value used as weak map key
Hello
The command pnpm build
started to fail suddenly. The error is very new to me.
pnpm -v
6.9.1
node -v
v16.0.0
here is the whole output
pnpm build
> [email protected] build C:\Users\wahbe\Documents\GitHub\waelio.com
> cross-env NODE_ENV=production vite-ssg build
[vite-ssg] Build for client...
vite v2.3.8 building for production...
✓ 148 modules transformed.
dist/index.html 1.56kb
dist/manifest.webmanifest 0.39kb
dist/ssr-manifest.json 17.98kb
dist/assets/virtual_pwa-register.c298aae9.js 0.36kb / brotli: 0.23kb
dist/assets/app.2e115a7d.js 14.60kb / brotli: 4.38kb
dist/assets/workbox-window.prod.es5.3ec2694c.js 5.07kb / brotli: 1.83kb
dist/assets/[...all].1736958e.js 0.22kb / brotli: 0.17kb
dist/assets/timeline.fbb95060.js 1.19kb / brotli: 0.56kb
dist/assets/index.d6f56c2f.js 3.72kb / brotli: 1.12kb
dist/assets/terms.30188bec.js 10.52kb / brotli: 2.80kb
dist/assets/privacy.a41dd229.js 13.82kb / brotli: 2.19kb
dist/assets/about.29969d21.js 0.66kb / brotli: 0.28kb
dist/assets/404.5aa7cd15.js 0.52kb / brotli: 0.30kb
dist/assets/home.60b6dea3.js 0.50kb / brotli: 0.30kb
dist/assets/contact.c764fb33.js 4.81kb / brotli: 1.67kb
dist/assets/index.b25c940d.css 0.22kb / brotli: 0.10kb
dist/assets/contact.81aceb69.css 1.02kb / brotli: 0.30kb
dist/assets/app.85bb450a.css 18.71kb / brotli: 3.89kb
dist/assets/index.20a20aff.js 93.83kb / brotli: 29.41kb
dist/assets/vendor.b40dd116.js 189.95kb / brotli: 59.69kb
[vite-ssg] Build for server...
vite v2.3.8 building SSR bundle for production...
✓ 54 modules transformed.
.vite-ssg-temp/manifest.webmanifest 0.39kb
.vite-ssg-temp/main.js 134.67kb
.vite-ssg-temp/assets/style.de8298f4.css 24.08kb
[vite-ssg] Rendering Pages... (6)
TypeError: Invalid value used as weak map key
at WeakMap.set (<anonymous>)
at normalizePropsOptions (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.prod.js:2770:15)
at createComponentInstance (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected]\node_modules\@vue\runtime-core\dist\runtime-core.cjs.prod.js:5532:23)
at renderComponentVNode (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected][email protected]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.prod.js:156:22)
at Object.ssrRenderComponent (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected][email protected]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.prod.js:484:12)
at C:\Users\wahbe\Documents\GitHub\waelio.com\.vite-ssg-temp\main.js:645:30
at renderComponentSubTree (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected][email protected]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.prod.js:222:13)
at renderComponentVNode (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected][email protected]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.prod.js:173:16)
at Object.ssrRenderComponent (C:\Users\wahbe\Documents\GitHub\waelio.com\node_modules\.pnpm\@[email protected][email protected]\node_modules\@vue\server-renderer\dist\server-renderer.cjs.prod.js:484:12)
at _sfc_ssrRender$3 (C:\Users\wahbe\Documents\GitHub\waelio.com\.vite-ssg-temp\main.js:796:24)
ERROR Command failed with exit code 1.
Any ideas? Thank you
app.vue
<script setup>
import { ref } from "vue";
let show = ref(false);
setTimeout(() => {
show.value = true;
}, 0);
</script>
<template>
<router-view v-if="show" />
</template>
You can try it,but I don't know why
So in my case there was an issue with the IconLoader config (using unplugin-icons and the default vitesse config) in the vite.config.ts
which caused a component which used the auto-import feature of the loader to crash in the ssg process.
// vite.config.ts -- problematic version
// https://github.com/antfu/vite-plugin-components
ViteComponents({
extensions: ['vue'],
// generate `components.d.ts` for ts support with Volar
globalComponentsDeclaration: true,
// auto import icons
customComponentResolvers: [
// https://github.com/antfu/vite-plugin-icons
ViteIconsResolver({
componentPrefix: '',
// enabledCollections: ['carbon']
}),
],
}),
// vite.config.ts -- fixed version
// https://github.com/antfu/vite-plugin-components
ViteComponents({
extensions: ['vue'],
// generate `components.d.ts` for ts support with Volar
dts: true,
// auto import icons
resolvers: [
// https://github.com/antfu/vite-plugin-icons
ViteIconsResolver({
componentPrefix: '',
enabledCollections: ['carbon'],
}),
],
}),
It seem to be a partial transformation for SFC parts, can you upgrade to the latest version of unplugin-vue-components
and unplugin-icons
to see if it fixes?
I am still having this issue even with the latest version of `unplugin-vue-components` and `unplugin-icons`.
Did you find a solution guys ?
Thanks
Edit: The issue on my side came from using a lowercase name for a component <servicecard />
instead of <ServiceCard/>
Remember to check the case, mac local case is not sensitive, but linux case sensitive. I also encountered this problem because of a wrong capitalization naming, and it was successfully resolved after modification.
Make sure you don't have any unclosed HTML tags or invalid HTML tags in the Markdown file.
I got this error because:
- I was missing the following in my
/pages/index.vue
(in case you're using vitesse and have thenuxtStyle
set to the defaultfalse
value in vite-plugin-pages)
<route lang="yaml">
meta:
layout: home
</route>
- a component that you've renamed but didn't updated into a page/layout where it was previously used.
components.d.ts
can actually give you a pretty decent hint! (withnuxtStyle: true
)
I'm getting this and have tried stripping out plugins to narrow it down, but I'm not getting anywhere with it. Is there a way to run vite-ssg
with an active debugger on so I can step through the code and extract what is causing it?
UPDATE: I went ahead and just added console log statements to the dependency files. Found out it was unresolved components, but were unresolved because I was removing plugins to find what the original error was; so I may update again.
UPDATE2: The culprit was the order of my plugins... I really wish Vue would give better error output.