opennextjs-netlify: [Bug]: Some requests receiving `"code":"ERR_INVALID_URL" `

Summary

Sometimes users get an invalid URL error message. I can’t catch the error or return gracefully because it happens outside of my handler.

This is what the log looks like when the user receives an error:

{
  "errorType": "TypeError",
  "errorMessage": "Invalid URL: /resources/all?category=alphabet-charts&page=2",
  "code": "ERR_INVALID_URL",
  "input": "/resources/all?category=alphabet-charts&page=2",
  "stack": [
    "TypeError [ERR_INVALID_URL]: Invalid URL: /resources/all?category=alphabet-charts&page=2",
    "    at new NodeError (internal/errors.js:322:7)",
    "    at onParseError (internal/url.js:270:9)",
    "    at parse (<anonymous>)",
    "    at new URL (internal/url.js:346:5)",
    "    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:71:22)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

The error points to this line of code: https://github.com/netlify/netlify-plugin-nextjs/blob/02053fdce786e26a5a6c60a9e38b9e05fd2ac0d3/src/templates/getHandler.ts#L90

I understand that the error is telling me /resources/all?category=alphabet-charts&page=2 is not a valid when given to new URL. The full URL must have been passed at some point in order to get routed to my function, but for some reason event.rawUrl sometimes contains the path and not the full URL? This doesn’t seem like it could be my side as it runs before my handlers.

Steps to reproduce

I have not been able reliably reproduce, i have had to follow the logs. It is happening consistently for some users, and never for others.

A link to a reproduction repository

https://github.com/AceCentre/acecentre.org.uk

Plugin version

4.2.7

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

No response

Your netlify.toml file

`netlify.toml`
[[redirects]]
  from = "/trustees"
  to = "/about/trustees"
  status = 301

[[redirects]]
  from = "/account"
  to = "/my-acecentre"
  status = 301

[[redirects]]
  from = "/ace-centre-learning/my-courses"
  to = "/my-acecentre/courses"
  status = 301

[[redirects]]
  from = "/about/staff-member/*"
  to = "/about/staff/:splat"
  status = 301

[[redirects]]
  from = "/project/*"
  to = "/projects/:splat"
  status = 301

[[redirects]]
  from = "/news/*"
  to = "/blog/:splat"
  status = 301

[[redirects]]
  from = "/project/*"
  to = "/projects/:splat"
  status = 301

[[redirects]]
  from = "/news"
  to = "/blog"
  status = 301

[[redirects]]
  from = "/getting-started/faqs-frequently-asked-questions"
  to = "/getting-started"
  status = 301

[[redirects]]
  from = "/services/training"
  to = "/learning"
  status = 301

[[redirects]]
  from = "/services/information"
  to = "/services/advice-information"
  status = 301

[[redirects]]
  from = "/services/information/feedback/"
  to = "/form/information-appointment-feedback"
  status = 301

[[redirects]]
  from = "/privacy"
  to = "/page/privacy"
  status = 301

[[redirects]]
  from = "/ace-centre-privacy-policy-3"
  to = "/page/ace-centre-privacy-policy-3"
  status = 301

[[redirects]]
  from = "/purchase-terms-and-conditions"
  to = "/page/purchase-terms-and-conditions"
  status = 301

[[redirects]]
  from = "/safeguarding-policies"
  to = "/page/safeguarding-policies"
  status = 301

[[redirects]]
  from = "/wp-content/*"
  to = "https://backend.acecentre.org.uk/wp-content/:splat"
  status = 200

[[redirects]]
  from = "/ace-centre-learning"
  to = "/learning"
  status = 301

[[redirects]]
  from = "/resources/copyright-and-licence-terms-for-non-profit-items"
  to = "/page/copyright-and-licence-terms-for-non-profit-items"
  status = 301

[[redirects]]
  from = "/consent-form-2"
  to = "https://forms.office.com/Pages/ResponsePage.aspx?id=bFwgTJtTgU-Raj-O_eaPrEio9bWrHCRGoqxiKrWB3RlUMTJIR0NZVTNKMklEMjJHQ0dLQ1ZGMDBKTiQlQCN0PWcu"
  status = 301

[[redirects]]
  from = "/services/assessment"
  to = "/services/assessments"
  status = 301

[[redirects]]
  from = "/resources/electronic-text-based-comparison-chart"
  to = "https://backend.acecentre.org.uk/resources/electronic-text-based-comparison-chart"
  status = 301

[[redirects]]
  from = "/resources/electronic-text-based-features-checklist"
  to = "https://backend.acecentre.org.uk/resources/electronic-text-based-features-checklist"
  status = 301

[[redirects]]
  from = "/resources/developing-using-communication-book-templates"
  to = "/resources/developing-using-communication-book"
  status = 301

[[redirects]]
  from = "/services/assessment/nhs-referral"
  to = "/services/nhs/assessments"
  status = 301

[[redirects]]
  from = "/resources/access-to-low-tech-symbol-based-resources-when-pointing-is-difficult"
  to = "/resources/paper-based-resources-to-support-communication-for-adults-with-progressive-conditions"
  status = 301

[[redirects]]
  from = "/resources/using-low-tech-symbol-based-systems-with-children"
  to = "/resources/access-to-paper-based-symbol-resources-when-pointing-is-difficult"
  status = 301

[[redirects]]
  from = "/resources/getting-started-aac"
  to = "/resources/all?category=made-by-ace&subcategory=e-books"
  status = 301

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

[[plugins]]
  package = "/netlify-plugins/sitemap"

[[plugins]]
  package = "/netlify-plugins/expose-env-variables"

[[plugins]]
  package = "/netlify-plugins/output-config"

[[plugins]]
  package = "/netlify-plugins/copy-redirects"

[build]
  command = "yarn build && yarn build-function"
  publish = ".next"

Your public/_redirects file

I put my redirect into the netlify.toml file rather than the _redirects file

Your next.config.js file

`next.config.js`
module.exports = {
  env: {
    IMAGE_URL: process.env.IMAGE_URL,
    CLOUDINARY_CLOUD: process.env.CLOUDINARY_CLOUD,
    CONTEXT: process.env.CONTEXT,
  },
  images: {
    domains: ["acecentre.org.uk", "internal.acecentre.org.uk"],
  },
};

Builds logs (or link to your logs)

N/A

Function logs

Function logs
{
  "errorType": "TypeError",
  "errorMessage": "Invalid URL: /resources/all?category=alphabet-charts&page=2",
  "code": "ERR_INVALID_URL",
  "input": "/resources/all?category=alphabet-charts&page=2",
  "stack": [
    "TypeError [ERR_INVALID_URL]: Invalid URL: /resources/all?category=alphabet-charts&page=2",
    "    at new NodeError (internal/errors.js:322:7)",
    "    at onParseError (internal/url.js:270:9)",
    "    at parse (<anonymous>)",
    "    at new URL (internal/url.js:346:5)",
    "    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:71:22)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}```

</details>


### .next JSON files

Too long to attach, let me know if you need them

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 18
  • Comments: 24 (5 by maintainers)

Most upvoted comments

This seems to be related to a change in the proxy. This is being rolled back.

even i am also facing same issue for root also

{
  "errorType": "TypeError",
  "errorMessage": "Invalid URL: /",
  "trace": [
    "TypeError [ERR_INVALID_URL]: Invalid URL: /",
    "    at new NodeError (internal/errors.js:322:7)",
    "    at onParseError (internal/url.js:270:9)",
    "    at new URL (internal/url.js:346:5)",
    "    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:71:22)",
    "    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
  ]
}

This has now rolled out to all nodes so everyone should have working responses. I’ll levae this issue open while we monitor. Thanks everyone for your help and patience!

+1 that this only occurs on SSR pages.

This also just started happening on 2 different projects of ours this morning, around 9am ET. It started out sporadically, but now it’s every single request that has server-side data fetching.

Feb 22, 09:05:14 AM: 5d04e454 ERROR  Invoke Error 	{"errorType":"TypeError","errorMessage":"Invalid URL: /_next/data/erwZDNQAvqN7G3Zd75Vwd/rooms/619262929891ff00014b2756.json?roomId=619262929891ff00014b2756","code":"ERR_INVALID_URL","input":"/_next/data/erwZDNQAvqN7G3Zd75Vwd/rooms/619262929891ff00014b2756.json?roomId=619262929891ff00014b2756","stack":["TypeError [ERR_INVALID_URL]: Invalid URL: /_next/data/erwZDNQAvqN7G3Zd75Vwd/rooms/619262929891ff00014b2756.json?roomId=619262929891ff00014b2756","    at new NodeError (internal/errors.js:322:7)","    at onParseError (internal/url.js:270:9)","    at parse (<anonymous>)","    at new URL (internal/url.js:346:5)","    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:53:22)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}
Feb 22, 09:05:14 AM: 5d04e454 Duration: 1.92 ms	Memory Usage: 178 MB	
Feb 22, 09:05:14 AM: f7178594 ERROR  Invoke Error 	{"errorType":"TypeError","errorMessage":"Invalid URL: /rooms/619262929891ff00014b2756","code":"ERR_INVALID_URL","input":"/rooms/619262929891ff00014b2756","stack":["TypeError [ERR_INVALID_URL]: Invalid URL: /rooms/619262929891ff00014b2756","    at new NodeError (internal/errors.js:322:7)","    at onParseError (internal/url.js:270:9)","    at parse (<anonymous>)","    at new URL (internal/url.js:346:5)","    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:53:22)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}

Thanks for your patience everyone! The status page should be updated shortly, and the deploy is being rolled back now.

I’m facing the same issue, please do something, this bug is affecting my current large number of users directly.

Same errors for our project. All server-side pages show this error with Invalid url. Plugin version: 4.2.4

Plugin version: 4.2.7

Same problem with NextJS SSR pages:

{"errorType":"TypeError","errorMessage":"Invalid URL: /","trace":["TypeError [ERR_INVALID_URL]: Invalid URL: /","    at new NodeError (internal/errors.js:322:7)","    at onParseError (internal/url.js:270:9)","    at new URL (internal/url.js:346:5)","    at Runtime.handler (/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js:71:22)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}

No report was logged into my Sentry.

Same here

Facing this issue with a very large site. No routes are working across all environments. No updates were made to the site when this outage occurred. This looks to be internal netlify functions failing and not this plugin itself.

Facing the same issue with every SSR page and API routes.

facing very same issue for my next config based redirect.

I’m facing the same issue, please do something, this bug is affecting my current large number of users directly.

Same … i am in stuck

Thank you so much Netlify team