React Native : bundling failed: Error: While trying to resolve module `@livechat/mitt`
React Native : 0.56.0 @livechat/livechat-visitor-sdk : 0.35.2
Hi Guys,
I am trying to integrate livechat in my react-native application using livechat-visitor-sdk npm package . I am not using react-native-livechat npm package as I want the UI to be customisable.
But react-native packager throws the following error while bundling the latest version of livechat-visitor-sdk :
error: bundling failed: Error: While trying to resolve module `@livechat/mitt` from file `PROJECT_PATH/node_modules/@livechat/livechat-visitor-sdk/dist/index.cjs.js`, the package `PROJECT_PATH/node_modules/@livechat/mitt/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`PROJECT_PATH/node_modules/@livechat/mitt/dist/livechat-mitt.native.js`. Indeed, none of these files exist:
After looking into the node_modules/@livechat/ directory , I could see two directories : livechat-visitor-sdk and mitt . The package.json file inside the mitt directory has a field named react-native which references file named dist/livechat-mitt.native.js . But there is no file named livechat-mitt.native.js under dist directory which is inside the mitt directory.
Is the crash happening because of this ? Currently I am using version 0.0.23 version used in the following example project : https://github.com/livechat/chat-window-react-native-example
While using version 0.0.23 version, there is no mitt directory and the project runs successfully. But the SDK lacks some methods as it is quite old version.
Is there a way I can make the version 0.35.2 work in my react-native project ?
Please let me know if I am missing any information that might be needed to resolve this issue.
Thank You.
Yes you are right, this problem is resolved in react-native-library so I highly recommend using it.
You can find livechat-visitor-sdk.js file there which you can copy and use separately if you want to have fully customisable component.
There are also some other issues solves like cookies handling etc.
Hi, @venits , what do you mean by react-native-library ? Are you saying react-native-livechat ?
Secondly, yes, I have livechat-visitor-sdk.js file. But how shall I use it so that I can get rid of the error ? Currently in old version 0.0.23 , there is not mitt directory, so I am not getting that error. But in newer version 0.35.2, the package.json file inside mitt directory , references dist/livechat-mitt.native.js which is not present.
Apologies, if I missed something.
Yep I mean this repo: https://github.com/livechat/react-native-livechat
Here is a link to livechat-visitor-sdk that you should use when working with react-native: https://github.com/livechat/react-native-livechat/blob/master/LiveChat/livechat-visitor-sdk.min.js
Hi @venits , initially I wanted to use the react-native-livechat package, but found it limiting in terms of customization of UI.
Like I want the chat window to be opened on a separate View, instead of the bubble that we get in react-native-livechat package. Do let me know if it is possible to achieve it.
So after having chat with the livechat support I decided to use the livechat-visitor-sdk .
For the minified file, correct me if I'm wrong, but are you suggesting that I download the livechat-visitor-sdk.min.js file locally in my project and import it as a module instead of relying on the livechat-visitor-sdk npm package ?
Let me know if I'm wrong in my assumption.
You are right.
You have to download file I provided to you.
Copy it into your project.
And then simply import:
import {init} from './livechat-visitor-sdk.min';
And use it as you normally would use Visitor SDK basing on these docs: https://developers.livechatinc.com/docs/visitor-sdk/
Thanks for the help @venits . I will follow the steps you provided.
So do I need to do this for every new version of livechat-visitor-sdk that gets released in future ?
If you store it locally in your component you don't have to worry about that.
There will be no major changes in livechat-visitor-sdk so I wouldn't worry about that 😄
Hi @venits ,
I stored it locally and imported the init method like you suggested . But I'm getting the following TypeError :
TypeError: Cannot read property 'split' of undefined.
Here is the stack-trace image of the redbox .

Am I doing something incorrect ?
You have just imported it and this error showed up? Or you used some functions from Visitor Sdk?
Hi @venits I imported it as follows ::
import { init } from "../lib/livechat-visitor-sdk.min";
And in constructor method I used the following code snippet :
this.visitorSDK = init({
license: my_licence_id
});
And I get this error just as I click on the screen.
I am using TypeScript, but that shouldn't make any difference right ? Are you able to reproduce this on your own end ?
Shall I use the un-minified version of the aforementioned file ? That is the livechat-visitor-sdk.js file ?
Yep it might be a problem with TypeScript. If you have opportunity please use Javascript. If not maybe try to pass your license as Number type or String type if you pass number.
What I mean:
this.visitorSDK = init({
license: "12312313"
});
instead of:
this.visitorSDK = init({
license: 12312313
});
Hi @venits Apologies for the late reply.
But I am getting error even when I try to pass license number as String type :

Is there anything you would like me to do so that I could provide you with better logs. ?
Hmm please add this snippet before importing this library.
GLOBAL.cookie = '';
That is really strange by the way I will look into this.
@venits GLOBAL.cookie = ''; did the work for me.
But is it the right way to solve it ? Let me know if I can help you on this.
@react-native-guy You can try version 1.1.3 it should work without GLOBAL.cookie
@venits Apologies but 1.1.3 version of what package are you talking about ?
Earlier you provided me the following file which I am using currently :
@react-native-guy Oh yeah sorry, I meant if you update package to version: 1.1.3. It should work without connecting livechat-visitor-sdk.min.js manually :) Also cookies problems is solved there also.
At least I hope so :D
@venits Thank you for the reply . I guess you are referring to the version 1.1.3 of react-native-livechat library. But like I described in the OP, I was using version 0.35.2 of @livechat/livechat-visitor-sdk to implement my own chat UI instead of using the react-native-livechat library.
But after facing the issues mentioned in OP, I decided to use the minified file as per your suggestions.
Can you guide me as to how can I get the changes that you introduced in version 1.1.3 of react-native-livechat library into my app?
Thank You.
@react-native-guy Hi, basically I replaced @livechat/livechat-visitor-sdk with my own minified version and defined GLOBAL.cookie = '' before importing it.
So there there should be no difference between my version and yours 👍
@venits So the GLOBAL.cookie = '' part that I have done in the minified file is good to go for now right ?
Or shall I update the @livechat/livechat-visitor-sdk to expect those changes ?
Will this change be included in future version of @livechat/livechat-visitor-sdk package. Or shall I keep using the changes I've made in the minified file ?
Apologies if I'm asking a naive question 😅.