Home
Support Forums

Runtime.UnhandledPromiseRejection on my Next.js app

I’m having a problem running ucid-hawking-30af2d which is a Next.js 11.0 application. My local setup works flawlessly on OSX, Windows, even Vercel.

The build works fine without any error, but when accessing the site, I get this error:

{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "TypeError: Cannot read property 'filter' of undefined",
  "trace": [
    "Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'filter' of undefined",
    "    at process.<anonymous> (/var/runtime/index.js:35:15)",
    "    at process.emit (events.js:314:20)",
    "    at processPromiseRejections (internal/process/promises.js:209:33)",
    "    at processTicksAndRejections (internal/process/task_queues.js:98:32)"
  ]
}

I tried to redeploy while clearing the cache and got the same issue.

The error can be seen live here:

https://614f4dec58cbee00070ffd19--lucid-hawking-30af2d.netlify.app/

The app’s code is available here:

https://github.com/Avansai/next-multilingual-example-netlify

@nbouvrette hello! just wanted to give you an update and let you know that i forked your repo and spent a long time digging through the source to figure out the REAL origin of this error. this filter error is a total red herring that’s a side effect of the actual failure point. the failure exists in/because of the MulLink component, which embedded in its helpers is a function that uses fs.readFileSync for several file manifests in the .next dist. this is not available in the runtime function environment on netlify by default. i’m currently exploring the right solution for you to get only the required files multilingual needs. i’ll update you if/when i have that! lastly, i’ll add that we’re in the middle of a plugin rewrite that i believe would possibly avoid the issue altogether. i’ll be sure to test the rewrite against this project.

1 Like

@nbouvrette ok, i think we should do just this (this is semi identical to what we do in our plugin rewrite for sites):

please add a netlify.toml to your project containing:

[build]
  command = "npm run build"
  publish = "out"

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

[functions]
  included_files = [".next/*.json"]

here’s my working demo: https://multiling-next.netlify.app/

1 Like

Thank you! seems like this was a hard one to troubleshoot. I’ll add this config file for now and please let me know if at some point we don’t need it anymore!

1 Like

@nbouvrette would you be down give our rewrite alpha a try? @netlify/plugin-nextjs-experimental - npm (please read the instructions on npm!). this will require you to uninstall the current plugin.

(note: for anyone else who may happen upon this comment – we’re only suggesting the alpha right now to certain users we think it could help. if it’s not suggested directly to you, we don’t recommend trying quite yet. we will be letting everyone know when it’s in beta and free to test out for all!)

apologies - i thought the instructions included this, but the alpha right now requires you to be on the latest version of next. thanks!!

I must be doing something wrong, but it’s not working. What I did:

  • remove the existing plugin from Netlify’s web UI
  • install the alpha plugin
  • added it in the [[plugin]] section (left the rest of the original config you provided intact)

I get the following error:

  • Plugin β€œ@netlify/plugin-nextjs-experimental” failed

Error: The directory β€œout” does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory. In most cases it should be set to the site’s β€œ.next” directory path, unless you have chosen a custom β€œdistDir” in your Next config. If you are using β€œnext export” then the Essential Next.js plugin should be removed. See Build Plugins | Netlify Docs for details.

Also, I presume the long-term goal would be to have this all within the Web UI?

hello! yes, the long term goal will be for this all to β€œjust work” for users :). my fault again – i didn’t write the instructions and so there are gaps i didn’t realize! please set your publish directory in your netlify.toml (or in the UI) to β€œ.next”.

Still getting a weird error (tried 2 different configs) - this is the latest one:


[build]
  command = "npm run build"
  publish = ".next"

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

[functions]
  included_files = [".next/*.json"]

Error:

8:30:50 AM: ────────────────────────────────────────────────────────────────
8:30:50 AM:   Plugin "@netlify/plugin-nextjs-experimental" internal error   
8:30:50 AM: ────────────────────────────────────────────────────────────────
8:30:50 AM: ​
8:30:50 AM:   Error message
8:30:50 AM:   Error: ENOENT: no such file or directory, lstat '/opt/build/repo/public'

Hi. Thanks for your patience! Could you upgrade the plugin again and see if that fixes it?

1 Like

By the way, can you guys fork my repo to test this? :slight_smile: The previous solution is working fine for us so if you think it will be easier to test the new plugin, feel free to use our project as a test app hehe:

Hi @nbovrette,

I’ve forked the repo and following the instructions here was able to update the next.js plugin.

The only change to the repo was within the netlify.toml:

[build]
  command = "npm run build"
  publish = ".next"

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

[functions]
  included_files = [".next/*.json"]

After deploying the site, wasn’t able to replicate the errors.

Great - I presume the goal will be to make this experimental plugin the default one moving forward?

i’m not an expert in next, but i do believe this is the goal, yes!

Great, let me know when it’s out of the β€œexperimental” state and I’ll be happy to update our current config :slight_smile: