serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.47k stars 457 forks source link

`pageS3Path` is not being passed in core/defaultHandler.ts #1846

Open jlaramie opened 3 years ago

jlaramie commented 3 years ago

Issue Summary

I noticed a weird error on some of my ISG pages and I think I tracked it down to a change introduced in 3.4.0 / https://github.com/serverless-nextjs/serverless-next.js/pull/1731/files . There seems to be a couple of files that were not updated to support the new pageS3Path property when calling triggerStaticRegeneration.

I don't fully understand all the connections but I think these files are at fault:

https://github.com/serverless-nextjs/serverless-next.js/compare/v3.3.0...v3.4.0 This shows all the changes from the pull request in 3.4.0. While I didn't test in the latest Alpha looking at the comparison I think it still exists as an issue https://github.com/serverless-nextjs/serverless-next.js/compare/v3.4.0...v3.5.0-alpha.1

Actual behavior

ERROR   Invoke Error    
{
    "errorType": "TypeError",
    "errorMessage": "Cannot read property 'replace' of undefined",
    "stack": [
        "TypeError: Cannot read property 'replace' of undefined",
        "    at /var/task/regeneration-handler-410de241.js:559:14",
        "    at runMicrotasks (<anonymous>)",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)",
        "    at async Promise.all (index 0)",
        "    at async Runtime.handler (/var/task/regeneration-handler-410de241.js:550:5)"
    ]
}

Expected behavior

pageS3Path should be included in the SQS event

Steps to reproduce

Screenshots/Code/Configuration/Logs

Versions

Additional context

Checklist

dphang commented 3 years ago

Are you using build.useV2Handlers? Those files referenced only apply when enabling that (it's basically a refactor of the handlers to be more platform agnostic, but right not it’s experimental and not enabled by default)

dphang commented 3 years ago

Based on the hash regeneration-handler-410de241.js it looks like you are not using the new v2 handlers. So those files referenced won't apply since they are for the new ones (and the regeneration event structure is different).

It is indeed failing on this line:

        const normalizedUri = regenerationEvent.pageS3Path
            .replace(`static-pages/${manifest.buildId}`, "")
            .replace(".js", "");

pageS3Path should be passed in from here: https://github.com/serverless-nextjs/serverless-next.js/blob/02bf313c287556980f95c540cfa8df04f5974b2e/packages/libs/lambda-at-edge/src/lib/triggerStaticRegeneration.ts#L41-L49

Can you try to inspect the SQS queue (poll it) and see what the message structure looks like? And probably also post what your default handler folder looks like just to confirm it's using the right version.