Error: Cannot find module Netlify functions using Nextjs

Hello I recently migrated my app from a create-react-app to nextjs. I have installed the Essential Next.js by netlify plugin for my project. However I’m unsure if I have structured my project correctly.

I have tried deploying the app today but am seeing an error when I navigate to the root page. There are no build errors but the error on the deployed app is:

"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'request'\nRequire stack:\n- /var/task/src/netlify/functions/next_index/nextPage/index.js\n- /var/task/src/netlify/functions/next_index/renderNextPage.js\n- /var/task/src/netlify/functions/next_index/next_index.js\n- /var/task/next_index.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module 'request'",
"Require stack:",
"- /var/task/src/netlify/functions/next_index/nextPage/index.js",
"- /var/task/src/netlify/functions/next_index/renderNextPage.js",
"- /var/task/src/netlify/functions/next_index/next_index.js",
"- /var/task/next_index.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
"    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
"    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
"    at Object.<anonymous> (/var/runtime/index.js:43:30)",
"    at Module._compile (internal/modules/cjs/loader.js:999:30)",
"    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
"    at Module.load (internal/modules/cjs/loader.js:863:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
"    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)",
"    at internal/main/run_main_module.js:17:47"

My package.json for react and Next is:

"next": "^10.1.3",
"react": "^16.14.0"

Any help with this would be greatly appreciated.


Hey there, @Huweey :wave:

Welcome to the Netlify Forums :netliconfetti: Thanks for sharing these details.

Before we dive in further, can you share your Netlify site id with us, as well as your github repo if it is public? Additionally, have you taken any other debugging steps since posting this four days ago?

Hi Hillary,

I have deployed a branch of my repo specifically for this issue which can be found at:

The repo is not public but I’m happy to share whatever config or other details you might need.

My package.json looks like:

“next”: “^10.0.6”,
“react”: “^16.14.0”

I have a Netlify.toml that looks like

command = “npm run build”
publish = “out”

package = “@netlify/plugin-nextjs”

NODE_ENV = “production”

and a next.config.js:

module.exports = {
// Target must be serverless
target: “serverless”,

Howdy @Huweey,
That Next setup looks reasonable to me! The error mentions the request module- does that exist in your package.json?

1 Like

Hi Jen, No it isn’t in my package.json, the only reference I can find of it in the project is in my package-lock.json as a dependency of the microsoft-signalr package.

@microsoft/signalr”: {
“version”: “3.1.7”,
“resolved”: “”,
“integrity”: “sha512-CC0sQom5SanAy7K6ueAmuWfsWcIv+mIoqUO3qXguPK7YUGx1O2geHgv567Gb4T52yWEXo5UQ1TCeDJecEnbSEg==”,
“requires”: {
“eventsource”: “^1.0.7”,
“request”: “^2.88.0”,
“ws”: “^6.0.0”

Please tell me if that’s incorrect but I didn’t think I needed dependencies directly in my package.json.

Edit: If it’s of any use, I import the @microsoft/signalr package in my /pages/index.js file and connect to a hub via WebSockets in a useEffect React hook.

Kind regards,

Hey @Huweey,
Ah, we use the package.json to know what dependencies to install in the build container for your build. Given the error you’re seeing, I’d try adding request to the package.json, triggering another build, and seeing what happens- I’ll be curious if you then get similar errors about missing the ws module so please let us know how it goes.

Hi Jen, thanks for the response.

I’ve added request to the package.json (“request”: “^2.88.2”)

Unfortunately the error message appears to be the same. You can see my latest build here:

Hi @Huweey :wave:

Thanks for sharing those details.

I have taken this to some of our Nextjs experts, and there are two next steps here.

  1. We will need a public repo we can follow so that we can reproduce this. You can create a new repo and share it in this thread. Would you be open to this?
  2. You can try esbuild via
    node_bundler = "esbuild"

Thank you!