Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Error with Sapper/Sanity build due to parser error in query

7 replies
Last updated: Nov 11, 2020
Hey I'm suddenly getting an error on my sapper/sanity build and can't find an explanation online, any ideas?
ClientError: Subscript ranges must have integer endpoints
    at onResponse (C:\Users\...\web\node_modules\@sanity\client\lib\http\request.js:27:13)

Nov 11, 2020, 9:16 PM
Hey there! Seems like a parser error - could you share the relevant query if possible? Are you using any subscript ranges like
anything[2..5]
in your query?
Nov 11, 2020, 9:20 PM
export function preload({ params, query }) {
        const numBooks = 12;
        const p = parseInt(query.p)
        const bookStart = p ? (p - 1) * numBooks : 0;
        const sort = query.sort ? query.sort : 'order(title asc)';
        const bookEnd = (p) * numBooks
        const bookSplice = '[' + bookStart + '...' + bookEnd + ']'
        const filter = 
{
            'bookCount': count(*[_type == 'book' 
                                    && defined(slug.current) 
                                    && !(_id in path("drafts.**"))
                                    && defaultBookVariant.price > 0
                                ]),
            'books': *[_type == 'book' 
                        && defined(slug.current) 
                        && !(_id in path("drafts.**"))
                        && defaultBookVariant.price > 0
                        ] {
                            ...,
                            "images": defaultBookVariant.images[0].asset->url,
                            authors[]->{name, slug},
                            "price": defaultBookVariant.price,
                            "binding": defaultBookVariant.binding,
                            ...}
                            | 
 + sort + bookSplice +                            
}
        return client
        .fetch(filter)
        .then(res => {
                const {bookCount , books} = res
                return { bookCount, books };
        }).catch(err => this.error(500, err));
Nov 11, 2020, 9:21 PM
Hey there! Seems like a parser error - could you share the relevant query if possible? Are you using any subscript ranges like
anything[2..5]
in your query?
Nov 11, 2020, 9:20 PM
this code is unchanged from working earlier this week though
Nov 11, 2020, 9:22 PM
Ok, that was a helpful direction. It seems like my code doesn't default properly and it puts undefined in the range
Nov 11, 2020, 9:26 PM
Sounds like you found the culprit! 🚀
Nov 11, 2020, 10:07 PM
Indeed! Thanks for the clue!
Nov 11, 2020, 10:08 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?