microsoft / microsoft/BotFramework-WebChat

Vitest is encountering failures specifically related to the botframework-webchat module.

Open
#5,011 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bot Services bug customer-reported needs-author-feedback
Dominant language
HTML
Stars
1.8k
Forks
1.6k
Avg merge
22h 58m
Merged PRs (30d)
2

Description

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: Edge (latest)

Which area does this issue affect?

Others or unrelated

What is the public URL for the website?

No response

Please describe the bug

Error Message:
The failure is manifested with the following error:

Error: require() of ES Module C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\mdast-util-from-markdown\dev\index.js 
from 
C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\botframework-webchat-component\lib\Attachment\Text\private\LinkDefinitions.js not supported.

Instead change the require of index.js in C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\botframework-webchat-component\lib\Attachment\Text\private\LinkDefinitions.js 
to a dynamic import() which is available in all CommonJS modules.

Versions:

  • vite: 5.0.11
  • vitest: 1.2.1
  • node: 18.2.0
  • typescript: 5.3.3
  • react: 18.2.0
  • botframework-webchat: 4.16.0

Investigation:
Upon investigation, it has been identified that an internal dependency named mdast-util-from-markdown is exclusively ESM (ECMAScript Module) compatible. This incompatibility prevents direct consumption of the main botframework-webchat module in the latest Node.js environments where tests are executed.

Proposed Solution:
The recommended approach for consumers of mdast-util-from-markdown should adhere to the following guidelines:

Refer to the installation instructions provided in the documentation of the module:
Installation Guidelines

Additionally, consumers can consult the example provided in the GitHub Gist by sindresorhus for further clarity on usage:
Usage Example

Note: Resolving this issue according to the proposed solution is expected to rectify the failing Vitest scenarios for the botframework-webchat module.

Do you see any errors in console log?
Error: require() of ES Module C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\mdast-util-from-markdown\dev\index.js from C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\botframework-webchat-component\lib\Attachment\Text\private\LinkDefinitions.js not supported.
Instead change the require of index.js in C:\office\bot-work\Skynet\TeamsDevOpsPortal\node_modules\botframework-webchat-component\lib\Attachment\Text\private\LinkDefinitions.js to a dynamic import() which is available in all CommonJS modules.
How to reproduce the issue?

Run tests using vitest consuming botframework-webchat npm package.

What do you expect?

Already propsed the solution above.

What actually happened?

Vitests start failing.

Do you have any screenshots or recordings to repro the issue?

NO

Adaptive Card JSON

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by running Vitest with the listed Vite, Node, TypeScript, React, and botframework-webchat versions, then inspect the LinkDefinitions.js dependency boundary involving mdast-util-from-markdown. The work is done when the botframework-webchat Vitest scenarios run without the CommonJS/ESM error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, react, typescript, vite
Domain
frontend, testing, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.