ReferenceError: window is not defined when importing progressive-image.js
See original GitHub issueI want to add https://github.com/craigbuckler/progressive-image.js to my vite-ssg app and do this by adding
import 'progressive-image.js/dist/progressive-image.js'
import 'progressive-image.js/dist/progressive-image.css'
to the main.ts
. On Build for server… i get ReferenceError: window is not defined.
I used vitesse as base and know it’s possible to create a module. But i cannot import the two resources in a isClient if clause.
Is there any way to import these resources only on client generation only?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
WebpackError: ReferenceError: window is not defined on Gatsby
When using third-party dependencies (such as your Bootstrap modal) your capability to access to window object disappears.
Read more >referenceerror: window is not defined, how to solve
Here's how to fix the “referenceerror: window is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >How to solve "window is not defined" errors in React and Next.js
A different solution is to load your Scroll component using dynamic imports and the srr: false option. This way your component won't even...
Read more >MiniCssExtractPlugin - webpack
This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-Demand-Loading of CSS...
Read more >Untitled
!localStorage. js world, window is not defined, window is only available in 23 ... 2020 · Working with Local Storage in a Blazor...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem here is that libraries that are not SSR/SSG aware should be loaded with
dynamic import
, for example, forprogressive-image
:or using
onMounted / beforeMount
hooks.You can see an example on
src/modules/pwa.ts
module onvitesse
template, where thevirtual:pwa-register
module (this guy will register theservice worker
) is loaded only ifisClient
istrue
.I have the same issue when I build for production (ReferenceError: window is not defined) while playing around with p5.js sketches using vitesse. I’d like to exclude the component from SSG but wrapping the components in <client-only> doesn’t work for me.