question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to encode .... of type object - Prismic.Predicate.at()

See original GitHub issue

Hello,

I’ve tried to use multiple predicates on a query as the example but when the code (see below) is executed I got an error: Unable to encode no-case-study of type object

const noCasesStudiesProjects = client().then(api => {
    return api
      .query([
        Prismic.Predicates.at('document.type', 'project'),
        Prismic.Predicates.at('document.tags', ['no-case-study'])
      ])
      .then(data => {
        return data.results;
      });
  });

I’m using : Nuxt 2.0.0 and prismic-javascript ^2.0.1

Any ideas ? Thanks

NB : Until yesterday, everything worked well 😕 NB2 : Seems to works in build and generate (nuxt) process 🧐

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
mcridercommented, Feb 8, 2019

Okay got a non-minified version of prismic-javascript library so i could debug it, looks like this comes down to this line: https://github.com/prismicio/prismic-javascript/blob/edd2c5b66926492dfabd0371100d9f2bc6b413c4/src/Predicates.ts#L41

Due to some awesome javascript idiosyncrasies, which may be dependent on the version of Node being used, instanceof won’t work here. Dropped in some logging, hope you find it as fascinating as I do 😛

  console.log(value); // [ 'articles', 'videos' ]
  console.log(typeof value); // object
  console.log(value instanceof Array); // false
  console.log(Array.isArray(value)); // true
  console.log(Object.prototype.toString.call(value)); // [object Array]

Can we switch to use one of the last two methods to test if its an array? Both fix the issue. @arnaudlewis ?

3reactions
Atinuxcommented, Mar 19, 2019

Thank you so much @mcrider for finding a workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to encode .... of type object - Prismic.Predicate.at() #77
Hello, I've tried to use multiple predicates on a query as the example but when the code (see below) is executed I got...
Read more >
Rest API Technical Reference - Documentation - Prismic
The query parameter (q) accepts a set of predicates (encoded as a URI component) as its value. Each predicate is enclosed in square...
Read more >
prismicio/client Technical Reference - Documentation - Prismic
Accepts a Custom Type API ID as a string, an array of document UID strings, and an optional params object. Queries your Prismic...
Read more >
Possible bug in PHP Predicates::at('document.type'
I have just started getting this error: regardless of which "page" number I set, the results are always from the first page!
Read more >
OR in Prismic predicate to return documents with two differen ...
Hello. I need to pull two different document types in the same query (preferably). For example: this.$prismic.api.query([ this.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found