"Cannot find module 'follow-redirects'"

Hello, I’m working on transferring a NextJS site over to Netlify, and I’m having trouble resolving an error:

Runtime.ImportModuleError: Error: Cannot find module 'follow-redirects'
Require stack:
- /var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js
- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
- /var/task/___netlify-handler.js
- /var/runtime/index.mjs
    at _loadUserApp (file:///var/runtime/index.mjs:997:17)
    at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1032:21)
    at async start (file:///var/runtime/index.mjs:1195:23)
    at async file:///var/runtime/index.mjs:1201:1

I’m using this command to do the deploy:

netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_ACCESS_TOKEN --build --prod --skip-functions-cache

I’ve included these dependencies in my package.json:

"@netlify/plugin-nextjs": "~4.37.4",
"@netlify/functions": "~1.6.0"

My netlify.toml config looks like this:

[[plugins]]
package = "@netlify/plugin-nextjs"

[build]
publish = ".next"

[build.environment]
NEXT_DISABLE_NETLIFY_EDGE = "true"

I’m using node 16.20.0. The project lives in a monorepo managed by rushjs using pnpm. The only information I’ve been able to find on the error message is that I need to include public-hoist-pattern[] = follow-redirects in my .npmrc file, but that doesn’t solve the error either.

Any ideas what I might be missing or what I can do to debug this? Since these are auto-generated Netlify functions creating this error and I don’t have any Netlify functions of my own I’m not sure how to get Netlify to properly find its dependencies.

Thanks for any help!

Hi @webly,

Since this is being discussed in the helpdesk as well, I think it’s better to continue the discussion there.

Hello @hrishikesh , i’m facing the same issue but i’m deploying with the web app. I’m new in the forum and i don’t know where i can find the helpdesk you are talking about. Can you tell me where i can take a look at it please ? Thank you !

Error message:

Runtime.ImportModuleError - Error: Cannot find module 'follow-redirects' Require stack: - /var/task/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/handlerUtils.js - /var/task/.netlify/functions-internal/_api_auth_nextauth-SPLAT-handler/_api_auth_nextauth-SPLAT-handler.js - /var/task/_api_auth_nextauth-SPLAT-handler.js - /var/runtime/index.mjs

Please share the name of the sit3, @Narchok. This usually happens if you’re using pnpm and not following our docs: Next.js on Netlify | Netlify Docs on the specific guidance.

Thank’s for you answer.
I was able to fix this problem by downgrading the netlify-plugin version to 4.36.1. Also i was missing of a env var as your link tell, i’ve added it and things work fine.
I’ll try to update the netlify-plugin later and see if it works still!