Closed jamaluddinrumi closed 1 year ago
very fast response
unfortunately, after upgrade to @unpic/pixels 1.2.0
, it yield another error appear on console log
chunk-X5MHFPH7.js?v=12e76c63:19 Module "http" has been externalized for browser compatibility. Cannot access "http.IncomingMessage" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
get @ browser-external:http:9
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/core/util.js @ util.js:5
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/client.js @ client.js:9
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/index.js @ index.js:3
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
(anonymous) @ _dnt.shims.js:1
chunk-X5MHFPH7.js?v=12e76c63:19 Module "querystring" has been externalized for browser compatibility. Cannot access "querystring.stringify" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
get @ browser-external:querystring:9
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/core/util.js @ util.js:11
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/client.js @ client.js:9
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/index.js @ index.js:3
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
(anonymous) @ _dnt.shims.js:1
util.js:13 Uncaught (in promise) ReferenceError: process is not defined
at node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/core/util.js (util.js:13:32)
at __require2 (chunk-X5MHFPH7.js?v=12e76c63:19:50)
at node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/client.js (client.js:9:14)
at __require2 (chunk-X5MHFPH7.js?v=12e76c63:19:50)
at node_modules/.pnpm/undici@5.22.1/node_modules/undici/index.js (index.js:3:16)
at __require2 (chunk-X5MHFPH7.js?v=12e76c63:19:50)
at _dnt.shims.js:1:67
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/core/util.js @ util.js:13
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/lib/client.js @ client.js:9
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
node_modules/.pnpm/undici@5.22.1/node_modules/undici/index.js @ index.js:3
__require2 @ chunk-X5MHFPH7.js?v=12e76c63:19
(anonymous) @ _dnt.shims.js:1
await in (anonymous) (async)
start @ (index):9784
childrenConnectedCallback @ (index):9784
await in childrenConnectedCallback (async)
connectedCallback @ (index):9784
I'm a bit confused why this is running in the browser. From the Astro code, it looks like it should be rendered on the server. This is what we'd expect, because you shouldn't be trying to generate placeholders in the client, as that defeats the purpose. Is there anything about your site that could be causing this to run in the browser?
I just ran a test using the unpic astro demo, with the exact code that you shared and it worked fine. Can you share a reproduction repo please
I just ran a test using the unpic astro demo, with the exact code that you shared and it worked fine. Can you share a reproduction repo please
sure, can i invite you as a collaborator to my repo for this purpose? because it's a private repo
If possible could you do a minimal reproduction instead. I've found it's generally hard to reproeuce these sort of things on actual sites, because I won't have things like API keys etc
okay, i'll try to create a minimal reproduction first
and will let you know when it's ready to be investigated
sorry, for late response
i've just created minimal repro but i assume the error is not because of @unpic/pixels
but another packages.
still trying to figure it out by myself.
you are welcome to close this issue if you wish.
OK, if you find out that it is related, please open a new issue
i've just found it
the problem is because i put the getPlaceholder()
into separated file (.ts)
// utils.ts
import { encode } from "blurhash";
import { getPixels } from "@unpic/pixels";
import { blurhashToCssGradientString } from "@unpic/placeholder";
const getPlaceholder = async (url:string) => {
const jpgData = await getPixels(url);
const data = Uint8ClampedArray.from(jpgData.data);
const blurhash = encode(data, jpgData.width, jpgData.height, 9, 4);
const placeholder = blurhashToCssGradientString(blurhash);
return placeholder
}
// somewhere .astro files
---
import { Image } from "@unpic/astro";
import { getPlaceholder } from "utils";
---
<Image
background={await getPlaceholder(`${photoMobileUrl}/m/618x618`)}
...
/>
when i put those together into one Astro files, the browser console log error is gone!
// somewhere .astro files & it works!
---
import { encode } from "blurhash";
import { getPixels } from "@unpic/pixels";
import { blurhashToCssGradientString } from "@unpic/placeholder";
const getPlaceholder = async (url:string) => {
const jpgData = await getPixels(url);
const data = Uint8ClampedArray.from(jpgData.data);
const blurhash = encode(data, jpgData.width, jpgData.height, 9, 4);
const placeholder = blurhashToCssGradientString(blurhash);
return placeholder
}
import { Image } from "@unpic/astro";
import { getPlaceholder } from "utils";
---
<Image
background={await getPlaceholder("some-image-file-from-cdn.jpg")}
...
/>
finally, thank's @ascorbic for this helpful library & your attentions 🙏
i use
@unpic/placeholder
with this codeand i got this error log