prismicio / javascript-kit

Development kit for the Javascript language
https://developers.prismic.io
106 stars 69 forks source link

Problem with Promises #102

Closed kristoferblack closed 8 years ago

kristoferblack commented 8 years ago

I'm getting an error when trying to use the promises syntax described on the readme:

Prismic.api("http://lesbonneschoses.prismic.io/api").then(function(api) {
  return api.query(""); // An empty query will return all the documents
}).then(function(response) {
  console.log("Documents: ", response.documents);
}, function(err) {
  console.log("Something went wrong: ", err);
});

I just keep getting Uncaught TypeError: Prismic.Api(...).then is not a function in console.

Any thoughts?

erwan commented 8 years ago

Hi,

What version of the kit are you using? Is it in NodeJS or in browser?

kristoferblack commented 8 years ago

Hey, I'm using the latest one, 2.0.1. I'm using it in the browser in a React app. Using Webpack.

erwan commented 8 years ago

I've fixed a few typos in the README but I don't think that was the cause of your problem.

Here the block of code works: https://jsfiddle.net/erwanl/ggbsbju5/

Can you post somewhere a minimal project where the issue is reproduced?

Basically the Prismic.api function is the getApi method: https://github.com/prismicio/javascript-kit/blob/master/lib/prismic.js#L71

Defined here: https://github.com/prismicio/javascript-kit/blob/master/lib/prismic.js#L27

and it does return a promise.

kristoferblack commented 8 years ago

Thanks for the info. I figured out the problem and it's totally on my end. It appears that NPM defaulted to installing an old version of the package... 1.4.0. I uninstalled and forced npm to install a fresh 2.0.1 version. Working now.