Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless CLI: Image Optimization Lambda seems to try using inexistent __dirname,"./threadChild.js" #373

Closed
celso-alexandre opened this issue Mar 1, 2024 · 4 comments

Comments

@celso-alexandre
Copy link

celso-alexandre commented Mar 1, 2024

open-next version: 2.3.6
System: Linux Mint Linux 5.15.0-88-generic #98-Ubuntu SMP Mon Oct 2 15:18:56 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Deploy:
I'm using serverless CLI. I may be missing something, maybe SST would've add the missing file before zipping it

before:package:createDeploymentArtifacts:
  - yarn open-next build --minify
  - mkdir -p ./.open-next/zips
  - cd .open-next/server-function && zip -r ../zips/server-function.zip .
  - cd .open-next/image-optimization-function && zip -r ../zips/image-optimization-function.zip .
  - cd .open-next/revalidation-function && zip -r ../zips/revalidation-function.zip .
  - cd .open-next/warmer-function && zip -r ../zips/warmer-function.zip .

My full serverless.yml: #32 (comment)

Description:
It seems that the generated "image-optimization" lambda is trying to import the file __dirname,"./threadChild.js", which was not generated

This is the cloudwatch log error I'm getting:

ERROR	Uncaught Exception 	
{
    "errorType": "Error",
    "errorMessage": "Cannot find module '/var/task/threadChild.js'",
    "code": "MODULE_NOT_FOUND",
    "requireStack": [],
    "stack": [
        "Error: Cannot find module '/var/task/threadChild.js'",
        "    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)",
        "    at Module._load (node:internal/modules/cjs/loader:985:27)",
        "    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)",
        "    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)",
        "    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)",
        "    at exports.emitMessage (node:internal/per_context/messageport:23:28)"
    ]
}

The following were produced by yarn open-next build
open-next version: 2.3.6
image
image

@celso-alexandre celso-alexandre changed the title Image Optimization Lambda seems to try using inexistent __dirname,"./threadChild.js" Serverless CLI: Image Optimization Lambda seems to try using inexistent __dirname,"./threadChild.js" Mar 1, 2024
@conico974
Copy link
Contributor

2.3.6 is broken with image opt, you can downgrade to 2.3.5 or set SHARP_VERSION="0.32.6" env variable before running open-next build.
Someone has reported an issue with 0.32.6 as well but i haven't had time to reproduce the issue yet and it seems that most people are managing to make it work with 0.32.6.
That's the PR for 2.3.6, there is more info here : #361

@celso-alexandre
Copy link
Author

celso-alexandre commented Mar 1, 2024

Thanks for replying, and I must say I'm very much amused by this piece of software, and I've learned a lot from it.
I've updated the description with my current serverless.yml definition.

I should add that after downgrading sharp to 0.32.6 and setting the variable as building SHARP_VERSION="0.32.6" yarn open-next build --minify, the lambda function "image-optimization-function" still produces an import of the inexistent file "./threadChild.js".
I will soon report back if the error persists

@khuezy
Copy link
Contributor

khuezy commented Mar 1, 2024

What next version are you currently on? sharp said https://github.com/vercel/next.js/releases/tag/v14.1.1-canary.28 fixed some things regards to it; can you try installing the latest 14.1.1 canary to see if it does indeed fix the problem?

@celso-alexandre
Copy link
Author

Thanks for helping. I can confirm after a couple tests that this exact line is not called anymore by changing the sharp version to 0.32.6. Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants