-
-
Notifications
You must be signed in to change notification settings - Fork 533
Jest fails on standard import syntax #869
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
Comments
Are you using Jest with TypeScript? If so, try doing two import statements: import { Tooltip } from 'react-tooltip';
import type { ITooltip } from 'react-tooltip';
|
Yes, Jest with TypeScript. Updated my code to separate imports but got the same error with Jest.
It seems to be highlighting this u.Fragment as the error in the minified output in case that is helpful?
|
This looks like something to do with build configuration, I'm not sure though. We'll see what we can do. |
Hi @clemenger, can you create a new app with Create React App and simulate your problem, please? Or share your app if it's possible. We'll try to test and solve this problem and let you know the status update. Thanks! |
Hi @danielbarion thank you for the prompt reply! Here's a sample repo using Create React App. |
Thanks for the fast reply with the example, we will take a look as soon as possible and let you know our findings! |
@clemenger for now the update is: I did a very quick test and I found some issues on Jest repository saying jest is not 100% compatible with es modules yet, so, when I tried with:
worked, can you check too, please? |
@danielbarion yes, the jest test worked for me with the umd file. However, similar to the attempted workaround with the .cjs file, the .umd file works for jest, but if you run
|
yeah, I don't have an answer yet. we need to do more research about this, do you have any suggestions? |
Not at the moment, I'll let you know if we come up with anything. |
I'm hitting this problem too. Any updates? |
- Add module entry for esm in package.json See https://rollupjs.org/guide/en/#publishing-es-modules: > To make sure your ES modules are immediately usable by tools that work > with CommonJS such as Node.js and webpack, you can use Rollup to > compile to UMD or CommonJS format, and then point to that compiled > version with the main property in your package.json file. If your > package.json file also has a module field, ES-module-aware tools like > Rollup and webpack 2+ will import the ES module version directly.
I opened up a pull request here: #881 . This fixed the issue for me in my project, and it also fixed all the issues in the example project posted above https://github.com/clemenger/react-tooltip-issue-869 . I just followed rollup recomendations here: https://rollupjs.org/guide/en/#publishing-es-modules |
Hi guys, version |
fix: package main should be cjs format. (fixes #869)
Thanks @KholdStare and @danielbarion, much appreciated.
See related https://stackoverflow.com/questions/73958968/ |
I had a similar case and the solution was:
which probably requires a special
|
When importing Tooltip, Jest throws the following error unless you specifically import the cjs version.
react-tooltip v5.2.0
To reproduce, in a project running Node 18, React 18, and Jest 29, import tooltip:
Project runs fine, but jest tests fail.
When running jest tests I see the following error:
So, it's possible it's just my jest configuration that is unable to support this syntax, but the tests run fine with standard imports from other react ui packages.
Current solution: directly import from the dist directory's .cjs version.
The text was updated successfully, but these errors were encountered: