-
-
Notifications
You must be signed in to change notification settings - Fork 22
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: Code Editor + Jest not working #111
Comments
You'll find easy reproduction steps in the README file of https://github.com/activenode-bugs/uiw-react-textarea-code-editor-jest |
|
Thanks for clarifying the difference. Can you imagine why the error of Once you are using your library anywhere with jest (no matter if just jest, |
The current repo test case is running fine, it has nothing to do with the library. This has a lot to do with build tools. |
I get that. But many people that use react also use And now I'm trying to figure out why this only happens with this specific library. I tried it with And I was expecting this one to work fine as well because your |
The official documentation confirms that https://www.npmjs.com/package/rehype#compatibility Which implies your package essentially can only support ESM as it depends on |
So I can see 3 possible options here:
If you choose option 1 that's completely fine, I just need the transparency so that I can switch back to our old Thank you so much! |
react-textarea-code-editor/package.json Lines 56 to 58 in 9288db6
Can be used together, depending on the build tool and your code. Iteration takes a while and is not that aggressive at the moment. It has some ways to do compatibility. |
Thanks for the hints. |
https://github.com/jaywcjlove/markdown-to-html-cli This is also a solution. |
Thank you, I will look into the suggestions. |
Hey @activenode which suggestion did you end up going with? |
@swyftx-simon Actually, since this turned to show more problems the more "workarounds" we tried to add , we had a large discussion and there are only 3 things I can recommend simply because of their convenience: Try:
Or else:
|
I managed to fix this issue by changing the import. Instead of used: |
Hey! Thanks for this library.
The Code Editor does not work when using Jest. One reason is Jest not supporting
import
statements natively but what I am not understanding is that it should be usingcjs
- but it is not.I created a down-to-earth, super-easy repository (it literally does nothing but importing your library and console.log). Just do
npm i
and runyarn jest
to trigger jest.https://github.com/activenode-bugs/uiw-react-textarea-code-editor-jest
You will see the error message of
Cannot use import statement outside a module
.I googled this for hours and tried multiple things but maybe I'm overlooking something. It will always end up in trying to load
unified
from therehype
library with animport
statement instead of going for a non-module approach.What works (which is not a satisfying solution):
I've looked into your package folder which contains
esm
,cjs
AND adist
folder. If you use jest withmoduleNameMapper
and then map@uiw/react-textarea-code-editor
to@uiw/react-textarea-code-editor/dist/editor.js
it will work / run.But the question is WHY? My first thought then is: Shouldn't your repo point
main: "dist/editor.js"
if this works seamlessly?Which triggers my follow up question why there even is
esm
,cjs
ANDdist
(can you clarify the differentiation?) and why doesdist/editor.js
work butcjs
does not?I feel like there is something weird going on which you can probably clarify as I am not as deep into this as you are :) Thank you so much in advance!
The text was updated successfully, but these errors were encountered: