question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using useServerlessTraceTarget with nextConfigDir causes a 503 in Cloudfront

See original GitHub issue

serverless-next.js v14.0 next.js v.9.3.1

I have useServerlessTraceTarget: true My next.config.js is in a different directory to the serverless.yml file so I’m using nextConfigDir: ../../../

I’m getting a 503 error on cloudfront when i deploy:

{
    "errorType": "Error",
    "errorMessage": "Cannot find module 'next/dist/next-server/server/render'\nRequire stack:\n- /var/task/pages/[static].js\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "code": "MODULE_NOT_FOUND",
    "requireStack": [
        "/var/task/pages/[static].js",
        "/var/task/index.js",
        "/var/runtime/UserFunction.js",
        "/var/runtime/index.js"
    ],
    "stack": [
        "Error: Cannot find module 'next/dist/next-server/server/render'",
        "Require stack:",
        "- /var/task/pages/[static].js",
        "- /var/task/index.js",
        "- /var/runtime/UserFunction.js",
        "- /var/runtime/index.js",
        "    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:840:27)",
        "    at Module.require (internal/modules/cjs/loader.js:1019:19)",
        "    at require (internal/modules/cjs/helpers.js:77:18)",
        "    at Object.KK5V (/var/task/pages/[static].js:947:18)",
        "    at __webpack_require__ (/var/task/pages/[static].js:31:31)",
        "    at Module.Nfsr (/var/task/pages/[static].js:1035:28)",
        "    at __webpack_require__ (/var/task/pages/[static].js:31:31)",
        "    at /var/task/pages/[static].js:126:18",
        "    at Object.<anonymous> (/var/task/pages/[static].js:129:10)"
    ]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukemarshdvcommented, Jul 8, 2020

I agree the pattern I’m using isn’t ideal but we have many origins and behaviours which differ for each application. We used to use terraform to populate these in Cloudfront but this plugin means I can’t use terraform anymore. if I could use this and continue to use terraform it would simplify the serverless files

0reactions
dphangcommented, Oct 11, 2021

@cweekly yes the maintainers of Next.js. They had a comment here (https://github.com/vercel/next.js/discussions/16276#discussioncomment-709863) and also ever since 10.2 or so the code splitting was changed and it seemed largely the same for serverlessTrace target (pages + shared chunks of JS are also generated, instead of previously tracing the dependencies into node_modules via the vercel/nft package)

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP 503 status code (Service Unavailable)
An HTTP 503 status code (Service Unavailable) typically indicates a performance issue on the origin server. In rare cases, it indicates that CloudFront ......
Read more >
Serverless Next.js Component - Serverless Framework: Plugins
Use the useServerlessTraceTarget option in serverless.yml . This will cause Next.js to not bundle dependencies into each page (instead creating lightweight ...
Read more >
npm:@sls-next/serverless-patched - Skypack.dev
In most cases you wouldn't want to use CloudFront's distribution domain to access your application. Instead, you can specify a custom domain ...
Read more >
Deploy your Next.js apps on AWS Lambda via Serverless ...
In most cases you wouldn't want to use CloudFront's distribution domain to ... responses errorPages: - code: 503 path: "/503.html" minTTL: 5 #...
Read more >
serverless-nextjs-plugin - Bountysource
Using webpack 5, returns the following from Cloudfront: 503 ERROR The request could not be satisfied. The Lambda function associated with the CloudFront...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found