serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

Since custom handlers are not copied to the regeneration lambda, use the default handler and ignore the customer handler when building the regeneration lambda

Open rsanchez opened this issue 3 years ago • 3 comments
trafficstars

When you use a custom handler option (mine is handler.js, so my config is handler.handler), the custom handler file gets copied to the default lambda and the image lambda, but not the regeneration lambda. However, the regeneration lambda still attempts to load the customer handler named in the options, and since that custom handler is not copied over, the regeneration lambda fails. This is the error I see:

{
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'handler'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/Runtime.js\n- /var/runtime/index.js",
    "stack": [
        "Runtime.ImportModuleError: Error: Cannot find module 'handler'",
        "Require stack:",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/Runtime.js",
        "- /var/runtime/index.js",
        "    at _loadUserApp (/var/runtime/UserFunction.js:221:13)",
        "    at Object.module.exports.load (/var/runtime/UserFunction.js:279:17)",
        "    at Object.<anonymous> (/var/runtime/index.js:43:34)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)",
        "    at internal/main/run_main_module.js:17:47"
    ]
}

Here's another person experiencing the same issue: https://github.com/serverless-nextjs/serverless-next.js/issues/1098#issuecomment-873509152

This PR use the default handler name and ignores the custom handler when building the regeneration lambda.

rsanchez avatar Aug 26 '22 21:08 rsanchez

Handler Size Report

No changes to handler sizes.

Base Handler Sizes (kB) (commit e6367b585fb98608cd2e9327e2c8d4058ba73b00)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1578,
            "Minified": 692
        },
        "Image Lambda": {
            "Standard": 1543,
            "Minified": 831
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1588,
            "Minified": 698
        },
        "Default Lambda V2": {
            "Standard": 1580,
            "Minified": 694
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1551,
            "Minified": 835
        },
        "Regeneration Lambda": {
            "Standard": 1233,
            "Minified": 566
        },
        "Regeneration Lambda V2": {
            "Standard": 1307,
            "Minified": 596
        }
    }
}

New Handler Sizes (kB) (commit f2940760aeaa3bd7d05d34c7f43db7771f378a21)

{
    "Lambda": {
        "Default Lambda": {
            "Standard": 1578,
            "Minified": 692
        },
        "Image Lambda": {
            "Standard": 1543,
            "Minified": 831
        }
    },
    "Lambda@Edge": {
        "Default Lambda": {
            "Standard": 1588,
            "Minified": 698
        },
        "Default Lambda V2": {
            "Standard": 1580,
            "Minified": 694
        },
        "API Lambda": {
            "Standard": 634,
            "Minified": 318
        },
        "Image Lambda": {
            "Standard": 1551,
            "Minified": 835
        },
        "Regeneration Lambda": {
            "Standard": 1233,
            "Minified": 566
        },
        "Regeneration Lambda V2": {
            "Standard": 1307,
            "Minified": 596
        }
    }
}

slsnextbot avatar Aug 26 '22 21:08 slsnextbot

Codecov Report

Merging #2484 (f294076) into master (e6367b5) will increase coverage by 0.02%. The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2484      +/-   ##
==========================================
+ Coverage   83.85%   83.88%   +0.02%     
==========================================
  Files         102      102              
  Lines        3717     3716       -1     
  Branches     1191     1190       -1     
==========================================
  Hits         3117     3117              
+ Misses        588      587       -1     
  Partials       12       12              
Impacted Files Coverage Δ
...rless-components/nextjs-component/src/component.ts 86.31% <ø> (-0.05%) :arrow_down:
packages/libs/core/src/images/imageOptimizer.ts 84.51% <0.00%> (+0.41%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Aug 26 '22 21:08 codecov[bot]

@telmperez does this error message relate to the issue you reported?

rsanchez avatar Aug 26 '22 22:08 rsanchez