question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Posting a request with a file produces error: Failed to construct 'URL': Invalid URL

See original GitHub issue

Versions:

  • @inertiajs/inertia version: ^0.10.1
  • @inertiajs/inertia-react version: ^0.7.1

Describe the problem:

When posting a request with the useForm helper that has a file, the browser reports an error as seen here:

    index.js:1 Uncaught TypeError: Failed to construct 'URL': Invalid URL
    at p (index.js:1)
    at e.n.visit (index.js:1)
    at e.n.post (index.js:1)
    at eval (index.js:1)
    at post (index.js:1)
    at handleSubmit (Edit.jsx:95)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070)

When I remove the file, everything posts fine.

Steps to reproduce:

Use the useForm helper hook to post a request with a file.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
wntechscommented, Sep 15, 2021

The issue still exist but I have come up with following solution -

change post(route('users.update', user.id)); to post(route('users.update', user.id).url());

0reactions
claudiodekkercommented, Dec 1, 2021

Closing this, as it appears to be a duplicate of https://github.com/inertiajs/inertia/issues/782

While we still use Ziggy’s route helper in the PingCRM demo app, we intend to replace this with template strings or hardcoded URLs in a future build. In part to work around issues such as these, but also to reduce the initial page render and to make our demo application more straight forward.

Personally, I consider the following to be good alternatives:

`/users/${user->id}/posts`

or something like

"/users/:user/posts".replace(":user", user.id)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unhandled exception rendering component: Failed to ...
It should be a valid URL in the format: "{AAD B2C INSTANCE}/{TENANT DOMAIN}/{SIGN UP OR SIGN IN POLICY}".
Read more >
TypeError: Failed to construct 'URL': Invalid URL - Treehouse
Hello, I'm attempting to use images and videos in my react component and I'm receiving one of two errors. Where I try the...
Read more >
How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >
How to Parse URL in JavaScript: hostname, pathname, query ...
How to easily parse URL in JavaScript and access components like hostname ... error; // => TypeError, "Failed to construct URL: Invalid URL"....
Read more >
Server error: The URL is invalid. It may refer to a nonexistent ...
Are you using the hostname, ip address or localhost to connect to the site? I would double check that. You could also try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found