sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

ImageFunction fails with "TypeError: Cannot read properties of undefined (reading 'getStore')" #457

Closed MisterJimson closed 6 days ago

MisterJimson commented 6 days ago

After updating to OpenNext v3 from v2, seeing the following in our logs.

Most requests to the ImageFunction lambda fail. Interesting in our UI, images generally seem to work, but we have seen a couple fail to display.

OpenNext: 3.0.5 SST: 2.43.3 NextJS: 14.2.4

{
   "message":"Uncaught Exception",
   "data":{
      "errorType":"TypeError",
      "errorMessage":"Cannot read properties of undefined (reading 'getStore')",
      "stack":[
         "TypeError: Cannot read properties of undefined (reading 'getStore')",
         " at sC.<anonymous> (file:///var/task/index.mjs:82:82590)",
         " at Object.onceWrapper (node:events:631:28)",
         " at sC.emit (node:events:517:28)",
         " at finish (node:internal/streams/writable:748:10)",
         " at process.processTicksAndRejections (node:internal/process/task_queues:82:21)"
      ]
   }
}
khuezy commented 6 days ago

If image optimization fails, it'll fall back to the original source. Your images are likely unoptimized; you can check in the developer tools in the Sources tab. As for the error, I'm not sure why getStore error, looks like globalThis.__als is undefined for you... not sure why.

We have an e2e test that checks for image optimization: https://github.com/sst/open-next/blob/main/packages/tests-e2e/tests/appRouter/image-optimization.test.ts and that appears to be working w/ the latest.

conico974 commented 6 days ago

Update to 3.0.6. Should be fixed there

MisterJimson commented 6 days ago

Fixed in 3.0.6! Thanks!