Cannot load ReactWebChat with requireJS. #5406
Labels
Bot Services
Required for internal Azure reporting. Do not delete. Do not change color.
bug
Indicates an unexpected problem or an unintended behavior.
customer-reported
Required for internal Azure reporting. Do not delete.
Is it an issue related to Adaptive Cards?
No
Is this an accessibility issue?
No
What version of Web Chat are you using?
Latest production
Which distribution are you using Web Chat from?
NPM
Which hosting environment does this issue primarily affect?
Web apps
Which browsers and platforms do the issue happened?
Browser: Chrome (latest), Browser: Edge (latest)
Which area does this issue affect?
Development experience
Which theme pack does this issue affect?
I did not test it on other theme packs
What is the public URL for the website?
No response
Please describe the bug
import ReactWebChat, { createDirectLine, createStore } from "botframework-webchat";
<ReactWebChat username={formData.current.name} activityMiddleware={middleWareHandle} directLine={directLineRef.current} styleOptions={{hideUploadButton:true}} onRenderActivity={() => { scrollToBottom(); }} />
this is how i am importing and using the component
This is my WebPack
Issue 1
When i bundle my code with webpack, i try to use the said bundle on a magento environment which is fully dependent on requireJS. I have tried both, amd and umd targetLibs, with each target, botframework-webchat does not want to load. I get this error: uncaught error mismatched anonymous define() module.
Issue 2
Since NPM package doesnt work, i was able to use the js bundle directly and bind it to window. This works like a charm, since i can use window bound functions from the package as to fullfill my dependencies. However, when the bundled code updates a state, there is an issue where i get this error: **Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.**
My assumption is that since the js bundle of the package comes with its own react instance, this causes the issue.
So basically I am not able to load the package via requiresJS due to incompatible bundling (since there is only 1 version of the bundle, its especially annoying) and If i try to use the js bundle in my react app directly, i cant since state updates break the code.
Please let me know if i am doing anything wrong.
Do you see any errors in console log?
How to reproduce the issue?
Load bundled js code (preferably umd for requireJS in this case):
Use bundle directly:
import React, { useState, useEffect, useRef } from "react"; function Chat() { const { ReactWebChat, createDirectLine, createStore } = window.WebChat; // Use global WebChat ... }
What do you expect?
Intended behavior should be:
What actually happened?
Failed to load bundled code on requireJS
Unable to use js bundles in react environment because of prepackaged react instance already present in bundle causing hook errors.
Do you have any screenshots or recordings to repro the issue?
No response
Adaptive Card JSON
Additional context
No response
The text was updated successfully, but these errors were encountered: