mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

mermaid module not found when running tests

Open lauraceconi opened this issue 1 year ago • 1 comments

Description

Hello, I just updated Mermaid to version 10.0.0 and now the tests in my app stopped working with the error Cannot find module 'mermaid' from './file.ts'. This was not occurring in previous versions (> 9.4.0). Everything works fine when running the app, this error is only happening on tests.

I did some investigation and found out that Jest actual error message is Error: No known conditions for "." entry in "mermaid" package. Adding the require entry, pointing to "./dist/mermaid.esm.mjs" in package.json solved the issue :)

Any specific reason to remove the require entry? Anyhow, I'm opening a PR adding it to package.json

Steps to reproduce

  1. Install mermaid in a React app
  2. Create a file importing mermaid as follows: import mermaid from 'mermaid'
  3. Create a test file for the previous created file
  4. Run tests
  5. See the error Cannot find module 'mermaid' from './file.ts'

Screenshots

No response

Code Sample

No response

Setup

Desktop

  • OS and Version: Mac
  • Browser and Version: Chrome

Additional Context

No response

lauraceconi avatar Feb 28 '23 17:02 lauraceconi

Opened the PR https://github.com/mermaid-js/mermaid/pull/4164

lauraceconi avatar Feb 28 '23 17:02 lauraceconi

I updated to 10.1.0 and ran into this. I had to downgrade to 9.4.3 to avoid test errors.

fdemello avatar Apr 21 '23 00:04 fdemello

We use Jest v26 and it still fails for us. Any idea, how to tackle it?

fabiradi avatar Sep 22 '23 13:09 fabiradi

@fabiradi Create empty mock js file for mermaid and add its path to moduleNameMapper in jest config file. It works for me.

// mermaid-mock.js

// eslint-disable-next-line @typescript-eslint/no-unused-vars
module.exports = (...args) => {
  //
};


// jest.config.js
module.exports = {
  ...
  moduleNameMapper: {
    ...
    mermaid: "<rootDir>/path_to_mock/mermaid-mock.js",
  }
}

StationSoen avatar Dec 05 '23 09:12 StationSoen

Hi, is there any solution? I'm still facing module not found issue when running jest framework. Thanks

zongqichen avatar Apr 18 '24 16:04 zongqichen