ascorbic / unpic-img

Multi-framework responsive image component

Home Page:https://unpic.pics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot build using `unpic/astro` when `output: 'server'` in Astro config

flayks opened this issue · comments

Describe the bug
I figured that I couldn't build my Astro site, and for some reason it was coming from undici. Looking at the lockfile, it is used by Unpic, then breaks the build when using the server output.

To Reproduce
Use Unpic for Astro for images with the following Astro config:

export default defineConfig({
    output: 'server',
    adapter: cloudflare({
        // mode: 'directory',
    }),

It might be linked to Cloudflare as well?

Repro URL: https://stackblitz.com/edit/withastro-astro-mxdlug?file=src%2Fpages%2Findex.astro

Expected behavior
It should build normally without error

I narrowed down and figured out that this is the root cause of my failed build

@hckhanh are you also using Cloudflare?

Just for the sake of making sure it works with other adapters, I tried with the Vercel and Node adapters, it builds fine.

@hckhanh are you also using Cloudflare?

Hi @ascorbic I am using Cloudflare

Could you both try updating @unpic/astro and see if it fixes it?

Hi @ascorbic I get this error when I try to re-add the Image component from @unpic/astro

<--- Last few GCs --->

[9479:0x158008000]    16657 ms: Scavenge 4049.1 (4127.1) -> 4048.5 (4127.8) MB, 4.75 / 0.00 ms  (average mu = 0.604, current mu = 0.390) allocation failure; 
[9479:0x158008000]    16668 ms: Scavenge 4049.9 (4127.8) -> 4049.2 (4137.8) MB, 9.83 / 0.00 ms  (average mu = 0.604, current mu = 0.390) allocation failure; 
[9479:0x158008000]    17193 ms: Mark-Compact 4056.0 (4137.8) -> 4053.6 (4144.3) MB, 516.71 / 0.00 ms  (average mu = 0.452, current mu = 0.079) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0x1010bd53c node::Abort() [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 2: 0x1010bd73c node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 3: 0x1012426c4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 4: 0x101416db8 v8::internal::Heap::GarbageCollectionReasonToString(v8::internal::GarbageCollectionReason) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 5: 0x101415894 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 6: 0x10140c0ac v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 7: 0x10140c90c v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 8: 0x1013f197c v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
 9: 0x1017d9444 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
10: 0x101b38c44 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
11: 0x107c6b12c 
12: 0x107c4e9fc 
13: 0x107c37ff8 
14: 0x107c37aec 
15: 0x107254e64 
16: 0x107c559a0 
17: 0x107c51460 
18: 0x107c6a410 
19: 0x10719814c 
20: 0x107ccb820 
21: 0x1071fa140 
22: 0x10745b830 
23: 0x101b5bee4 Builtins_ArrayMap [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
24: 0x101ab03e4 Builtins_InterpreterEntryTrampoline [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
25: 0x101ab03e4 Builtins_InterpreterEntryTrampoline [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
26: 0x101ab03e4 Builtins_InterpreterEntryTrampoline [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
27: 0x101ae7210 Builtins_AsyncFunctionAwaitResolveClosure [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
28: 0x101b94fb8 Builtins_PromiseFulfillReactionJob [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
29: 0x101ad6b94 Builtins_RunMicrotasks [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
30: 0x101aae3f4 Builtins_JSRunMicrotasksEntry [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
31: 0x101384238 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
32: 0x101384724 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
33: 0x101384900 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
34: 0x1013abacc v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
35: 0x1013ac268 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
36: 0x100fecc64 node::InternalCallbackScope::Close() [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
37: 0x100fec7c4 node::InternalCallbackScope::~InternalCallbackScope() [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
38: 0x101063930 node::Environment::RunTimers(uv_timer_s*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
39: 0x101a8ac44 uv__run_timers [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
40: 0x101a8e4a4 uv_run [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
41: 0x100fed754 node::SpinEventLoopInternal(node::Environment*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
42: 0x1010fdb8c node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
43: 0x1010fd928 node::NodeMainInstance::Run() [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
44: 0x1010876b8 node::Start(int, char**) [/Users/khanh/Library/pnpm/nodejs/20.11.0/bin/node]
45: 0x1805510e0 start [/usr/lib/dyld]
sh: line 1:  9479 Abort trap: 6           astro check

Is that when building or running? Are you able to share a reproduction?

When I build the project locally:

import cloudflare from '@astrojs/cloudflare'
import { defineConfig } from 'astro/config'
import tailwind from '@astrojs/tailwind'
import react from '@astrojs/react'


// https://astro.build/config
export default defineConfig({
  prefetch: true,
  output: 'server',
  adapter: cloudflare({ imageService: 'cloudflare' }),
  integrations: [react(), tailwind({ nesting: true, applyBaseStyles: false })],
  image: { remotePatterns: [{ protocol: 'https', hostname: 'www.datocms-assets.com' }] },
})

I will create a reproduction when I am free. Now I am busy though

Thanks

I've managed to reproduce it. Interestingly that OOM error is coming from astro check - it seems to actually build fine. I'll investigate to see if I can find out why it's crashing.

OK, it seems it's unrelated to Unpic, and is actually about astro check running on your dist folder. To fix it, add this to your tsconfig.json:

{
  "extends": "astro/tsconfigs/strict",
+  "exclude": [
+    "dist"
+  ]
}

This is the problem withastro/language-tools#721