Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Components using Copy fails unit tests fail due to missing module 'es-toolkit/compat' #18403

Closed
2 tasks done
ainulmdr opened this issue Jan 22, 2025 · 7 comments · Fixed by #18639
Closed
2 tasks done
Assignees
Labels
severity: 2 https://ibm.biz/carbon-severity type: bug 🐛

Comments

@ainulmdr
Copy link

Package

@carbon/react

Browser

No response

Package version

1.74.0

React version

18.3.1

Description

When running unit tests, components using Copy produces the following error and prevents test suite from running:

`Test suite failed to run

Cannot find module 'es-toolkit/compat' from 'node_modules/@carbon/react/lib/components/Copy/Copy.js'                                                                                                            
                                                                                                                                                                                                                
Require stack:                                                                                                                                                                                                  
  node_modules/@carbon/react/lib/components/Copy/Copy.js                                                                                                                                                        
  node_modules/@carbon/react/lib/components/CodeSnippet/CodeSnippet.js                                                                                                                                          
  node_modules/@carbon/react/lib/index.js`

I have attached the project:
react-failure.zip

Reproduction/example

NIL

Steps to reproduce

  1. npm install
  2. npm test

Suggested Severity

Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

@Sam-Wool
Copy link
Contributor

Sam-Wool commented Jan 24, 2025

My team was able to apply a workaround to our jest tests by adding an entry to moduleNameMapper in jest.config.ts to point directly to the directory in question in our node_modules.

Image

@tay1orjones
Copy link
Member

This might be because es-toolkit/compat was introduced in [email protected]. You might have another dep using es-toolkit that is using an old version. yarn why es-toolkit or npm ls es-toolkit should list out what packages are using it and the corresponding versions.

If there's multiple versions you'll need to unify them by either

  1. updating the deps that rely on es-toolkit
  2. force all usages to resolve to one version via a resolutions key in your package.json

@tay1orjones
Copy link
Member

We had a report of this on slack but they weren't using Jest at all. I took another look today and noticed that es-toolkit uses the exports field. It looks like Jest didn't support that until v28, jestjs/jest#9771.

In the case of this error being not related to tests and happening in a build, I would think it could be the same root problem, just present elsewhere in the tooling chain. The bundler maybe being on an older version that didn't handle exports correctly. Or could even be from using an old version of Node too.

In any case this appears to be toolchain related and not something we can take direct action on, so I'm going to close this for now.

@github-project-automation github-project-automation bot moved this from 🕵️‍♀️ Triage to ✅ Done in Design System Feb 6, 2025
@priyanaka07
Copy link

This bug is still not fixed, making entire IBM carbon unusable!!!

@tay1orjones
Copy link
Member

@priyanaka07 Sorry you're still running into this. It's going to depend on your toolchain's support of exports. You can downgrade your version of @carbon/react to bypass this issue, but you're likely to hit it again with your other dependencies as they begin using exports.

I found another piece to the puzzle that may be helpful if you're using create-react-app, react-scripts v4, or webpack v4: facebook/create-react-app#10892

Upgrading to react-scripts@^5 resolves this issue by migrating to Webpack 5, which correctly supports the exports field in package.json.

@matejoslav
Copy link
Contributor

@tay1orjones hello, we are encountering same issue when running tests, will try workaround mentioned above. We have react-scripts v5 and use carbon/react v1.76.0, npm ls es-toolkit only shows carbon using v1.32.0 of es-toolkit

@tay1orjones
Copy link
Member

I think this can be solved by updating the import paths to hit the compat module directly, rather than relying on module resolution of bundlers that are causing these issues. Will have a PR up shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: 2 https://ibm.biz/carbon-severity type: bug 🐛
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

5 participants