-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't avoid crash when trying to discriminate between build environment and client side. #230
Comments
I got the same issue when working with |
check for |
I am having this issue as well, even with tests for It seems like this problem is what the |
@YannDuv @earlAchromatic can you provide a minimal repro? |
See repro here: https://github.com/earlAchromatic/vite-ssg-build-v-client or use Details are in the README. Note that I did solve the issue on my end - it turned out to be library specific. I left the repro in case you want to look anyways. I am still curious why |
@earlAchromatic I've found the problem with I'll check updating the 3d-force-graph/package.json "type": "module",
"sideEffects": false,
"exports": {
".": {
"require": "./dist/3d-force-graph.common.js",
"import": "./dist/3d-force-graph.module.js",
"types": "./dist/3d-force-graph.d.ts"
}
}, three-forcegraph/package.json "type": "module",
"sideEffects": false,
"exports": {
".": {
"require": "./dist/three-forcegraph.common.js",
"import": "./dist/three-forcegraph.module.js",
"types": "./dist/three-forcegraph.d.ts"
}
}, |
it works (loading jsdom before SSR entry), but then I get some errors loading
we also need to patch this another package: three-render-objects/package.json "type": "module",
"sideEffects": false,
"exports": {
".": {
"require": "./dist/three-render-objects.common.js",
"import": "./dist/three-render-objects.module.js",
"types": "./dist/three-render-objects.d.ts"
}
}, and then we got another error from [vite-ssg] An internal error occurred.
[vite-ssg] Please report an issue, if none already exists: https://github.com/antfu/vite-ssg/issues
file:///F:/work/projects/quini/GitHub/issue-repro/vite-ssg-issues/vite-ssg-build-v-client-master/node_modules/.pnpm/@vueuse+core@8.3.1_vue@3.2.33/node_modules/@vueuse/core/index.mjs:500
mediaQuery = window.matchMedia(query);
^
TypeError: window.matchMedia is not a function |
@earlAchromatic with your repo and applying previous patches, I can now use this on the <script setup>
import ForceGraph3D from '3d-force-graph'
onMounted(async () => {
// const ForceGraph3D = await import('3d-force-graph')
const N = 300
const gData = {
nodes: [...Array(N).keys()].map(i => ({ id: i })),
links: [...Array(N).keys()]
.filter(id => id)
.map(id => ({
source: id,
target: Math.round(Math.random() * (id - 1)),
})),
}
ForceGraph3D()(document.getElementById('3d-graph')).graphData(gData)
})
</script>
<template>
<div id="3d-graph" />
</template> |
A small fix allowing use export const isDark = typeof window !== 'undefined' && typeof window.matchMedia !== 'undefined' ? useDark() : ref(false)
export const toggleDark = useToggle(isDark) build just works: F:\work\projects\quini\GitHub\issue-repro\vite-ssg-issues\vite-ssg-build-v-client-master>pnpm run build
> @ build F:\work\projects\quini\GitHub\issue-repro\vite-ssg-issues\vite-ssg-build-v-client-master
> vite-ssg build
[vite-ssg] Build for client...
vite v2.9.7 building for production...
✓ 370 modules transformed.
dist/index.html 0.83 KiB
dist/ssr-manifest.json 13.02 KiB
dist/assets/app.3b68aa3a.js 793.00 KiB / gzip: 220.18 KiB
(!) Some chunks are larger than 500 KiB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
[vite-ssg] Build for server...
vite v2.9.7 building SSR bundle for production...
✓ 8 modules transformed.
.vite-ssg-temp/main.mjs 3.36 KiB
[vite-ssg] Rendering Pages... (1)
dist/index.html 1.22 KiB
[vite-ssg] Build finished. |
@earlAchromatic here the same repo patching the deps to use https://github.com/userquin/vite-ssg-build-v-client-master |
@userquin Nice work! Thank you taking a deep dive into it. Patch script is great 😄 |
@earlAchromatic if you want to also use |
I have a dialog that has a dependency on @a11y/focus-trap which is a web component.
As it is a web component, it uses stuff like document.createElement('template').
So I need to prevent it from being imported during SSG.
I tried 2 solutions without success :
Leads to the following error:
Which is the only way in the documentation to prevent running code in SSG. I used it around all usage of the dialog component that does the import.
Sadly it doesn't change anything.
It would be nice to have an identified solution in the documentation to prevent code from running during SSG.
The text was updated successfully, but these errors were encountered: