React-native-gifted-chat: RNGC not working with RN v0.49

Created on 5 Oct 2017  路  18Comments  路  Source: FaridSafi/react-native-gifted-chat

Issue Description

RNGC uses moment library.
Moment library uses dynamic strings.
This results in bundling errors:

"require() must have a single string literal argument"

Steps to Reproduce / Code Snippets

Upgrade RN to 0.49 and try to build/run the project

Expected Results

Be able to run the project.

Additional Information

  • React Native version: 0.49.1
  • react-native-gifted-chat version: 0.2.7
  • Platform(s) (iOS, Android, or both?): Both
bug help wanted

Most helpful comment

I've sent a PR which makes this module work with [email protected] for me, but I'm not sure If it doesn't break something else: https://github.com/FaridSafi/react-native-gifted-chat/pull/605

All 18 comments

@FaridSafi Just wanted to add, the current version of react-native-parsed-text RNGC (0.0.18) is also breaking RN v0.49+. Updating react-native-parsed-text to 0.0.19 should fix this.

I did go ahead and created an issue (https://github.com/moment/moment/issues/4206) for the moment.js library. As I need this to work in order to update our production app, I will go ahead and spent a few hours trying to solve this, as for moment.js, they are quite slow so I properly end up using a fork until accepted a PR. When I do I will post the fork here in case someone else in interested.

Found out that they are already working on a fix, at the moment the PR (https://github.com/moment/moment/pull/4187) is in the process of being merged. For now you can use this fork for moment.js (https://github.com/tqc/moment/tree/no-dynamic-import)

@DannyvanderJagt what actually fix it for you?
Did the update of react-native-parsed-text solve it? or we have to wait for the merge fix from "moment"?

@StanSarr Replacing moment@latest with the no-dynamic-import branch fixed it for me, at least for react-native-gifted-chat

@DannyvanderJagt, thanks for your comment.
I tried removing moment and installed no-daynamic-import branch, but still get the same error.
Will you please let me know how you fixed it in detail?

@gurudev51 if you're using react-native 0.49.x, I had the same issues because "moment" is used by metro-bundler, I downgrade from 0.49.x to 0.48.x.
npm start -- --reset-cache
and Run Xcode
That works for me.
Let us know :)

According to this issue on metro-bundler updating the moment.js dependency should be enough (lib side) - until it gets update lib side this should be possible this way.


Edit: apparently it doesn't work.
Going to do a small PR now.


Edit 2: Here it is.

It's nice to find out that moment released a new version with a fix for React-Native 0.49.x. @kelset Thank you for the PR!

This Issue can be closed, further comments are best placed in the PR.

I tried updating react-native-parsed-text and moment.js both but seems like it is still not working for me. I updated my package.json as following https://github.com/yalamber/react-native-gifted-chat/blob/master/package.json and in my apps package.json added "react-native-gifted-chat": "yalamber/react-native-gifted-chat#master", as dependencies.

@yalamber take a look at this PR: https://github.com/FaridSafi/react-native-gifted-chat/pull/523

@DannyvanderJagt

FYI @kelset @StanSarr

What about change moment library? It has a lot of issues around react-native (crashes, performance, object mutabilities, etc). The worst thing here is their comment https://github.com/facebook/metro-bundler/issues/65#issuecomment-335615159 comparing webpack users with react-native users (WTF).

There are other libraries for the same task:

  • date-fns (here a fork of this repo https://github.com/FaridSafi/react-native-gifted-chat/compare/master...mauron85:feature/date-fns)
  • js-joda

For me the issue still persists, even though I use the fixed version with the most recent moment dependency from this fork https://github.com/brunocascio/react-native-gifted-chat.git

Until this is fixed, for those starting a new project, this will work:

react-native init chat --version [email protected]

Starting a new project and downgrading will not work:

react-native init
npm install --save [email protected]

This is due to the fact that react-native will use a different file structure for each version and downgrading results in other incompatabilities.

@brunocascio I agree, it is definitely something to consider. There are definitely better alternatives with a more active community with the benefit of more frequent updates and better stability.

Let's investigate this by creating a new issue for this where we can gather some thoughts on this topic.

@DannyvanderJagt @brunocascio the moment team just released version 2.9.1 which supposedly should fix every issue we had. I'm happy to update my PR if needed, it seems a much lower hanging fruit than refactoring the lib to move away from it.


Edit: oh sorry didn't see my PR was merged already since I haven't seen it into the Release Notes. Anyway I'll try to update to 2.9.1 on my local and will let you know.

Hi @kelset!

Thanks for your feedback!

I have tried moment 2.19.1 and it works, but not in RN 0.49. If someone else has faced the same issue, let me know, please.

After upgrading (and using moment 2.19.1) I got this error: https://github.com/facebook/metro-bundler/issues/73#issuecomment-336008817

I'll be waiting for Facebook answers in that repository.

Thanks!

I've sent a PR which makes this module work with [email protected] for me, but I'm not sure If it doesn't break something else: https://github.com/FaridSafi/react-native-gifted-chat/pull/605

Thanks @doomsower !

Fixed in v0.2.9 馃檶

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yazhengwang picture yazhengwang  路  3Comments

SytzeAndr picture SytzeAndr  路  3Comments

cassioseffrin picture cassioseffrin  路  3Comments

emilkarl picture emilkarl  路  3Comments

luisfuertes picture luisfuertes  路  3Comments