mermaid
mermaid copied to clipboard
mermaid module not found when running tests
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
- Install
mermaid
in a React app - Create a file importing
mermaid
as follows:import mermaid from 'mermaid'
- Create a
test
file for the previous created file - Run tests
- 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
Opened the PR https://github.com/mermaid-js/mermaid/pull/4164
I updated to 10.1.0 and ran into this. I had to downgrade to 9.4.3 to avoid test errors.
We use Jest v26 and it still fails for us. Any idea, how to tackle it?
@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",
}
}
Hi, is there any solution? I'm still facing module not found issue when running jest framework. Thanks