POST is not a valid request method

I’m getting this error when running wrangler dev for one of my workers.
Using wrangler 1.16.0
Also tried reverting to 1.15.1 and 1.15.0 and had the same results.
I don’t believe this comes from my code of from a library that I’m using.
Production works ok. I didn’t try to publish again to production because I didn’t want to risk production.

Any ideas? Clues?

Here’s the full log:

Uncaught (in promise)
i: POST is not a valid request method
    at i [as constructor] (worker.js:1:42588)
    at new i (worker.js:1:42822)
    at worker.js:1:3465
    at worker.js:1:2233
    at Object.next (worker.js:1:2338)
    at worker.js:1:1250
    at new Promise (<anonymous>)
    at t (worker.js:1:995)
    at i.getAssetFromKV (worker.js:1:2964)
    at worker.js:1:5817
Uncaught (in response)

Do you have a small reproduction script for this issue?

Hi @arunesh90 , here’s a minimal repo, with practically no code, that shows the issue GitHub - danbars/wrangler-no-post-error: demonstrate issue with wrangler dev that has exception when using POST

  1. Clone the repo
  2. Run npm install
  3. Run npm run serve (or just wrangler dev)
  4. From POSTMAN (or any other client) run some POST request. This is the one that I used:
curl --location --request POST 'http://localhost:8787/f/s49oshid13l1ra427k3eqt' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode '[email protected]' \
--data-urlencode 'name=Joe' \
--data-urlencode 'Color=Grey2'

You should see the same error as I did

P.S, versions that I use:
wrangler 1.16.0
node v12.19.0
npm 7.11.0
MacOS 10.15.5

Thanks!

I’m unable to reproduce this issue at my side with that repo

1 Like
  1. What software versions are you using?
  2. Maybe there’s a difference because you’re not logged-in to my account with wrangler?
  3. Any other piece of config that we should look at, which might be different between us?

More details:
when published or run through wrangler preview everything works correctly. Only local run via wrangler dev is failing with that error

Seem to be related to Worker Site: POST is not a valid request method & How to Password Protect?
@whistles can you say if in your case it happened in wrangler dev or after you actually published it?

Published

My guess would be that you’re still somehow using the code from your in-production worker. I would suggest to do a fresh clone of your reproduction repo in another folder, and also change the name in your wrangler.toml to a different one like tasks-repo.
And just to be safe, I would also change the route in it to a different route that’s not in use.

And then with that try to reproduce the issue again, as I’m not sure what else it could be then.

@arunesh90 , the problem is that I somehow run locally the code of another worker.
I have api worker and a site worker.
Somehow, when I run wrangler dev locally I get the site.
I tried re-cloning the repo, rebuilding everything as you suggested, and it still happens.
I tried other workers that I have, and they work fine.
I tried wrangler preview and it runs the correct code - the api and not the site.
I tried cleaning the browser cache, and also running from other clients (postman, FireFox) and it still happens.
The dist folder looks right - it contains the api code and not the site’s code

This is my api wrangler.toml:

name = "api"
type = "webpack"
account_id = "c4a4xxxxxxxxx1710"
workers_dev = false
route = "https://api.form-data.com/*"
zone_id = "f6b7xxxxxxxxxxx6e15"

And this is my site’s wrangler.toml

name = "form-data-site"
type = "webpack"
account_id = "c4a4xxxxxxxxxx1710"
workers_dev = false
route = "https://form-data.com/*"
zone_id = "f6b7xxxxxxxxxxx6e15"

[site]
bucket = "./dist/pwa"
entry-point = "workers-site"

Is there some cache to local wrangler cli itself?
Any other idea?

UPDATE:
I tried changing the route and name, didn’t do any difference.

Also adding an explicit [dev] section like below didn’t do anything

[dev]
ip = "0.0.0.0"
port = 9000
local_protocol="http"

When I removed the route and zone, and instead set workers_dev = true, even with the same api name, it worked correctly.

I thought maybe my site’s routing is taking over all other workers, since it is routed to the root of the domain. But I checked, and there’s no wildcard there.
This is the site’s routing

This is the api’s worker routing
image

Any idea would be helpful, thanks!