serverless-next.js: Error: Cannot find module 'next/dist/next-server/server/node-polyfill-fetch'

While deploying a Next.js app to AWS using Serverless, I get a 503 error. When I drill down into the logs, I find the error I’m recieving is Error: Cannot find module 'next/dist/next-server/server/node-polyfill-fetch'.

I’ve tried uninstalling and reinstalling. I was using the latest version of Next. I tried to downgrade to 9.3.4. I’ve tried to downgrade Serverless Next.js. I’ve tried downgrading Node from 12 to 10 in Cloudfront. Any help would be greatly appreciated.

Please let me know if there is any other information needed to help with this issue.

“serverless-next.js”: “^1.13.0” “next”: “^9.3.4”

Full error message

{
    "errorType": "Error",
    "errorMessage": "Cannot find module 'next/dist/next-server/server/node-polyfill-fetch'\nRequire stack:\n- /var/task/pages/_error.js\n- /var/task/index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
    "code": "MODULE_NOT_FOUND",
    "requireStack": [
        "/var/task/pages/_error.js",
        "/var/task/index.js",
        "/var/runtime/UserFunction.js",
        "/var/runtime/index.js"
    ],
    "stack": [
        "Error: Cannot find module 'next/dist/next-server/server/node-polyfill-fetch'",
        "Require stack:",
        "- /var/task/pages/_error.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.mctB (/var/task/pages/_error.js:269:18)",
        "    at __webpack_require__ (/var/task/pages/_error.js:23:31)",
        "    at Module.rMRU (/var/task/pages/_error.js:321:106)",
        "    at __webpack_require__ (/var/task/pages/_error.js:23:31)",
        "    at /var/task/pages/_error.js:91:18",
        "    at Object.<anonymous> (/var/task/pages/_error.js:94:10)"
    ]
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 34 (7 by maintainers)

Most upvoted comments

@DeerajTheepshi yep, it is a bug you found in ISR, the component should handle if it’s part of standard Next.js build.

I will try to reproduce it but from seeing the code here (https://github.com/serverless-nextjs/serverless-next.js/blob/ee99374bd07674fc8a45622920eb2f17b9a51ff9/packages/libs/lambda-at-edge/src/build.ts#L397-L397) it seems to be copying same things as for the default lambda. If you could share a min repro it will be faster to debug. Thanks!