prismicio / javascript-kit

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

Error w/ React-native : unable to resolve module http #111

Closed philohelp closed 6 years ago

philohelp commented 8 years ago

I get a red screen when I try to require Prismic. It says

Unable to resolve module http from .../node_modules/prismic.io/lib/requests.js: Invalid directory /Users/node_modules/http

I'm reaching the API directly with Fetch but SDK would have been appreciated.

Edit: no better results with 2.1.0 (saw the release comment on react-native). Now it says : [error][tid:main] Unable to resolve module es6-promise from .../node_modules/prismic.io/lib/browser.js: Invalid directory /Users/node_modules/es6-promise I got rid of that but then got the same error as with 2.1.3. Did the dirty job...

erwan commented 8 years ago

Hi,

It's a known issue, the RN loader will load the modules even if they're in a conditional.

I recommend you to use the compiled version in the meantime: https://npmcdn.com/prismic.io@2.1.3/dist/prismic.io.js https://npmcdn.com/prismic.io@2.1.3/dist/prismic.io.min.js

philohelp commented 8 years ago

Ok many thanks for the quick reply. Would you have a short usage example on how it works with Fetch ?

P.S React being now more popular than JQuery, it would be great to have a specific kit (but I cant do it myself yet :-)

erwan commented 8 years ago

You actually don't have to use fetch, but it's used internally by the kit in order to work.

Here is a React (not native) example, but it should work the same: https://github.com/erwan/react-starter

philohelp commented 8 years ago

Quite exactly what I needed (and nice code), thanks !

chandlervdw commented 7 years ago

@erwan if I've got other teammates installing node_modules via npm, what's the best way to reference v3.2.0 so that I can utilize Prismic within my RN project?

chandlervdw commented 7 years ago

I found alw-react-native-prismic.io by @arnaudlewis which works with React Native! Hopefully that lib won't get shunned...

arnaudlewis commented 7 years ago

A whole new version of the javascript-kit is close to be ready, it's designed to work in pair with the Prismic api v2 which handle default value to prevent null runtime exception. In this version, we will make sure that you can use it with react native out of the box. For this version of the kit, it can be consider to add support for react native but not in priority.

scottbrassfield commented 7 years ago

Hi, I'm just hooking up Prismic to a RN project, and i wanted to check what is the currently recommended method of getting the SDK working with RN. I just installed prismic.io to my project and I am still getting the 'http' missing module error. Is the alw-react-native-prismic.io package mentioned above still the best way to get started?

arnaudlewis commented 7 years ago

@scottbrassfield If you just started with prismic.io on this project, I suggest you to use the API V2 because you can manipulate the response as pure Json instead of calling functions from prototype like getImage etc. You also have default values in the API to prevent null checking on the template part. Finally, you can replace prismic.io by prismic-javascript which is perfect for API V2 and I made sure the fix I put in my lib alw-react-native-prismic.io are there in prismic-javascript so I think it's the best way. So because of the new kit, I no longer maintain the other lib for React native. If you need the API V2, tell me and I'll activate it for your repo and I'll explain you everything you need to know.

scottbrassfield commented 7 years ago

@arnaudlewis thanks for the quick response! I just replaced prismic.io with prismic-javascript in my project. If you could help me get started with API V2 that would be great, this is actually my first time using prismic.io in general so any help getting started with the API would be greatly appreciated.

arnaudlewis commented 7 years ago

I'd be happy to help. I can invite you on the prismic club, it's a slack channel with a dedicated part for the new API, I'll lead you from here.

scottbrassfield commented 7 years ago

Sounds great, just got the slack channel working, thanks!

levimykel commented 6 years ago

This issue is resolved by using the prismic.io API v2 with the prismic-javascript kit.