QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.68k stars 1.29k forks source link

Ability to import client-side library via package management #2057

Closed aeroxy closed 1 year ago

aeroxy commented 1 year ago

Is your feature request related to a problem?

If the library I'd like to import has document operation, qwik will give me this error:

[vite] Internal server error: document is not defined

Describe the solution you'd like

For pure client-side library, we have have a "client-side" folder in src, all the files inside should be preloaded to the html document (hydration).

Describe alternatives you've considered

Use solid.js

Additional context

No response

shairez commented 1 year ago

thanks @aeroxy !

Can you give a specific example of a client side script you're loading and where do you try to load them?

(a repro-repo using https://qwik.new will be awesome)

Thanks!

aeroxy commented 1 year ago

thanks @aeroxy !

Can you give a specific example of a client side script you're loading and where do you try to load them?

(a repro-repo using https://qwik.new will be awesome)

Thanks!

It's our internal core SDK for Shopee. I will need to make a minimal example, which might take a while.

jonsam-ng commented 1 year ago

I encountered such problems some times, different result like window is not defined, self is not definbed or document is not defined. I wonder if import modules is working on server, if so, how can we import client side modules. Now I have two alternative methods, binding event on window:onload or useClientEffect$(), and I use dynamic import to load modules. But it's really not so convenient.

d-kls commented 1 year ago

@manucorporat i saw in issue #1315 that inlining is not recommended. It works for me in dev but not in production unless i change the entry strategy of the qwikVite plugin to "hook" (which is probably not optimal). I'm using leaflet and some leaflet plugins that when imported regularly will throw window is not defined, forcing me to inline the imports in useVisibleTask$. What is the correct way to handle this?