chi icon indicating copy to clipboard operation
chi copied to clipboard

type *http.Request has no field or method SetPathValue when use tinygo build to wasm

Open cxjava opened this issue 1 year ago • 1 comments

I am attempting to utilize the Chi router in a WASM module, but I encounter an error during the build process with TinyGo. I'm uncertain whether the issue originates from Chi or TinyGo. Would you be able to assist in diagnosing the problem?

tinygo build -o ./build/app0.wasm -target wasm 
# github.com/go-chi/chi/v5
../../../../go/pkg/mod/github.com/go-chi/chi/[email protected]/path_value.go:18:5: r.SetPathValue undefined (type *http.Request has no field or method SetPathValue)

go version : go version go1.23.1 darwin/amd64 tinygo version: tinygo version 0.33.0 darwin/amd64 (using go version go1.23.1 and LLVM version 18.1.2)

package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"
)

func main() {
	r := chi.NewRouter()
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("welcome"))
	})
	http.ListenAndServe(":3000", r)
}

cxjava avatar Sep 15 '24 05:09 cxjava

@angelofallars would you like to take a look?

It looks like the build tags in path_value.go and path_value_fallback.go introduced in https://github.com/go-chi/chi/pull/901 should account for tinygo too?

VojtechVitek avatar Sep 18 '24 20:09 VojtechVitek

Hi @angelofallars Could you help to take a look? Thank you!

cxjava avatar Oct 30 '24 00:10 cxjava

I've created a pull request to resolve this issue https://github.com/go-chi/chi/pull/978

efraimbart avatar Feb 12 '25 22:02 efraimbart