primatejs / primate

Web framework focused on flexibility and developer freedom
https://primatejs.com
MIT License
211 stars 9 forks source link

Cannot read properties of undefined (reading 'replace') when using GO module #169

Open JoakimMellonn opened 4 hours ago

JoakimMellonn commented 4 hours ago

When trying to use the Go module for having a backend in go, I'm getting the following error when running the app. This is a problem with a newly setup app.

$ npx -y primate@latest
primate 0.32.6
++ starting web build in development mode
file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/mark.js:4
  formatted.replace(`{${i}}`, bold(param)), format);
            ^

TypeError: Cannot read properties of undefined (reading 'replace')
    at file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/mark.js:4:13
    at Array.reduce (<anonymous>)
    at default (file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/mark.js:3:46)
    at make_error (file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/log.js:23:8)
    at normalize (file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/log.js:31:5)
    at Object.error (file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/private/log.js:59:20)
    at default (file:///Users/**/sandbox/primate-test/node_modules/@primate/go/src/private/error/faulty-route.js:5:35)
    at Object..go (file:///Users/**/sandbox/primate-test/node_modules/@primate/go/src/private/build.js:170:7)
    at async post (file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/build/hook/build.js:128:5)
    at async file:///Users/**/sandbox/primate-test/node_modules/@primate/core/src/build/index.js:41:3

Node.js v20.18.0

Steps for reproduction

  1. Setup a new primate app with minimum modules.
  2. Install the go module.
  3. Create a go simple route.
  4. Run the app.
terrablue commented 3 hours ago

Hey, thank you for reporting the issue.

I've created a reproduction at https://github.com/primatejs/issues/tree/169 which includes a simple Go route that returns plaintext.

You can run it with

git clone -b 169 https://github.com/primatejs/issues && cd issues && npm install && npx primate

Browsing to http://localhost:6161 displays Hello, world!

The faulty route error (which fails to display here -- will investigate why) could indicate that primate cannot find Go in path, which it needs to compile routes. Does go version work for you?

If this is not a problem of Go itself missing, could you send a small PR against this branch with the reproducible error? You might be doing something different in your Go route.