Closed Chosey98 closed 6 months ago
I'm looking into this and seems the issue is that WebChat doesn't currently support ESM environments properly
Here is the working example of WebChat + NextJS: https://stackblitz.com/edit/stackblitz-starters-e38mut?file=app%2Fpage.tsx
Oh it worked, Could you please elaborate more on why did it work like that? @OEvgeny
@Chosey98 if using regular top-level imports, despite use-client
directive it looks like NextJS imports WebChat on the server, which doesn't work as WebChat is designed to work in the browser.
In browser, in order to include WebChat into the same component tree, we need to use the same React and ReactDOM distributions. This means not only React and ReactDOM versions should match, but the actual imported modules should be the same.
For such cases WebChat provides a way to use exact React and ReactDOM versions. All you need is to expose them to window as window.React
and window.ReactDOM
.
At this point, this seems the best way possible to handle dependencies in browser. In future we may be able to use ES modules and import maps to handle this.
@OEvgeny for the build to succeed, you need to change the return of the provider to this:
return function WebChatProvider(props) { return <WebChatContext.Provider value={WebChat} {...props} />; };
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?
No response
Which area does this issue affect?
Others or unrelated
What is the public URL for the website?
No response
Please describe the bug
I'm trying to use the Component in a page.tsx (I'm using 'use client' for client side rendering) but it always returns this error:
Here is the code for the page.tsx
I think the problem is mostly generating from the createDirectLineSpeechServices but I'm not using it in the first place, I tried even commenting them in the index.ts but that also didn't work
Do you see any errors in console log?
How to reproduce the issue?
What do you expect?
The ReactWebChat component should render
What actually happened?
It's not rendering and produces the error above
Do you have any screenshots or recordings to repro the issue?
No response
Adaptive Card JSON
No response
Additional context
No response