'Require cycle issue when using BotFramework DirectLine JS with axios
I'm trying to work with Microsoft Bot Framework in react native using DirectLine API. Everything works properly but as soon as I initiate axios GET call I get error
Require cycle: node_modules/core-js/internals/microtask.js -> node_modules/core-js/internals/microtask.js
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
It only happens when I intialize DirectLine API, if I comment out and remove the DirectLine API, the axios works fine. Both are different APIs, I'm unable to figure out why using DirectLine API is causing the axios to stop working.
Here is the code
import React,{useEffect} from 'react';
import {
SafeAreaView,
View,
TouchableOpacity,
} from 'react-native';
import { DirectLine } from "botframework-directlinejs";
var directLine
const App = () => {
useEffect(()=>{
directLine = new DirectLine({
secret: "XXXXX"
});
directLine?.activity$.subscribe(botMessage => {
alert("BotMessage")
});
},[])
const onSend = () => {
let msgPayload = {
from: { id: 'abc', name:'human'},
type: 'message',
text: "Hello"
}
directLine.postActivity(msgPayload).subscribe(() => console.log("success"), () => console.log("failed"));
};
const onApiSend = () => {
const axios = require('axios').default;
axios.get('https://api.github.com/users/mapbox')
.then((response) => {
alert("Api Called Success")
});
}
onApiSend only works if I remove the useEffect (DirectLine JS) part. Otherwise I get error related to Require cycle
Solution 1:[1]
The issue is in the BotFramework DirectLine JS library and in order to make it work in react native, the library needs to be rebuild (both lib and dist) folder with minor change. The github repo should be forked and the line in BotFramework-DirecLineJS/src/directLine.ts should be changed from
import 'core-js/features/promise';
to
import 'core-js/modules/es.promise.finally';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ammar26 |
