Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JoakimMellonn opened this issue Nov 16, 2024 · 6 comments

Comments

@JoakimMellonn
Copy link

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
Copy link
Contributor

terrablue commented Nov 16, 2024

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.

@JoakimMellonn
Copy link
Author

Thank you for the very quick reply @terrablue! I have just tried running the reproduction you've made. Unfortunately this results in the samme error as before for me.

To be absolutely sure, I have run this on both my private (MacBook) and my workstation (Both in Windows and WSL) - same error on all three.

Here's the output from running the command you gave:

$ git clone -b 169 https://github.com/primatejs/issues && cd issues && npm install && npx primate
Cloning into 'issues'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 1), reused 13 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (14/14), done.
Resolving deltas: 100% (1/1), done.

added 33 packages, and audited 34 packages in 9s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities
primate 0.32.6
++ starting web build in development mode
file:///Users/**/sandbox/issues/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/issues/node_modules/@primate/core/src/private/mark.js:4:13
    at Array.reduce (<anonymous>)
    at default (file:///Users/**/sandbox/issues/node_modules/@primate/core/src/private/mark.js:3:46)
    at make_error (file:///Users/**/sandbox/issues/node_modules/@primate/core/src/private/log.js:23:8)
    at normalize (file:///Users/**/sandbox/issues/node_modules/@primate/core/src/private/log.js:31:5)
    at Object.error (file:///Users/**/sandbox/issues/node_modules/@primate/core/src/private/log.js:59:20)
    at default (file:///Users/**/sandbox/issues/node_modules/@primate/go/src/private/error/faulty-route.js:5:35)
    at Object..go (file:///Users/**/sandbox/issues/node_modules/@primate/go/src/private/build.js:170:7)
    at async post (file:///Users/**/sandbox/issues/node_modules/@primate/core/src/build/hook/build.js:128:5)
    at async file:///Users/**/sandbox/issues/node_modules/@primate/core/src/build/index.js:41:3

Node.js v20.18.0

$ go version
go version go1.21.0 darwin/arm64

@primatejs primatejs deleted a comment from ralyodio Nov 18, 2024
@terrablue
Copy link
Contributor

@JoakimMellonn I just published @primate/go@0.1.5 which should solve the issue on Mac. The repro repo now executes there, could you please confirm?

On Windows, it might take a while since I don't know a standardised way to query an application's path (like which on Unix). I'd need to research that.

@terrablue
Copy link
Contributor

terrablue commented Nov 18, 2024

@JoakimMellonn I just published @primate/go@0.1.6 which should solve the issue on Windows, please confirm.

@terrablue
Copy link
Contributor

@JoakimMellonn did this work for you?

@primatejs primatejs deleted a comment from ralyodio Dec 4, 2024
@JoakimMellonn
Copy link
Author

@JoakimMellonn did this work for you?

Yes, sorry for not getting back to you! It works on Linux and MacOS, but I haven't gotten the chance, to test it on Windows as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants