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

Seemingly unpredictable syntax errors when running codegen. #7268

Open
hyldmo opened this issue Jul 29, 2024 · 0 comments
Open

Seemingly unpredictable syntax errors when running codegen. #7268

hyldmo opened this issue Jul 29, 2024 · 0 comments
Assignees
Labels

Comments

@hyldmo
Copy link

hyldmo commented Jul 29, 2024

Describe the bug

I'm migrating over to @sanity/codegen from the old sanity-codegen package, but I'm stuggling to generate code for my groq queries. I'm getting syntax errors in all but 1 query. I initially thought it was caused by imported query fragments like this:

import { SEO } from './seo'

export const BLOG_PREVIEW = groq`
	${SEO}
`

But the syntax errors doesn't appear only there, I also get them places like this. The code is based on the https://www.sanity.io/templates/akva-hydrogen-sanity-demo template, so I'd assume most of it is idiomatic groq. The code works fine in the app itself, so I'm unsure if the error messages are accurate. Maybe there's something that happens when the fragments are concatenated?

import groq from 'groq'

export const COLOR_THEME = groq`
	text {
		hex,
		rgb,
		alpha
	},
	background {
		hex,
		rgb,
		alpha
	},
	background2 {
		hex,
		rgb,
		alpha
	}
`

To Reproduce

I have created a repro repository: here
Just run npm i && npm run codegen to see the errors.

Expected behavior

I expect the codegen to run without errors, or at least a better / more descriptive error message.
"Syntax error in GROQ query at position 158". Is that character 158 in the query? Even when glancing at those positions in the queries I have, I see nothing that looks like invalid syntax.

Which versions of Sanity are you using?

@sanity/cli           3.52.2 (up to date)
@sanity/codegen       3.52.2 (up to date)
sanity                3.52.2 (up to date)

What operating system are you using?

MacOS Sonoma 14.5 (23F79)

Which versions of Node.js / npm are you running?

10.8.1
v20.16.0
@linear linear bot added the question label Aug 6, 2024
@sgulseth sgulseth self-assigned this Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants