Comments (15)
I get that. But many people that use react also use jest
. And since jest
does not natively support ESM
modules (only very experimental support) it leads to problems when it detects an import statement.
And now I'm trying to figure out why this only happens with this specific library. I tried it with react-simple-code-editor
before and that one worked fine.
And I was expecting this one to work fine as well because your main
says cjs/index.js
so it should (and does) point to the cjs file. However then again it somehow tries to access (somewhere in between) rehype
package which then contains a import statement and I'm really trying hard to grasp the underlying problem as it really only appears with this library.
from react-textarea-code-editor.
@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:
- Switch on experimental ESM support in Jest (https://jestjs.io/docs/ecmascript-modules)
- Switch to vitest which in many cases is super low effort because it's mainly compatible to Jest
Or else:
We and the teams switched to vitest but also we switched to @codemirror
as we experienced more and more problems we couldn't solve with this react-textarea-code-editor
.
@codemirror
is freaking good but it's documentation isn't that easy. Everything's an extension in the newest CodeMirror but feel free to ping me directly for further questions. We basically switched to CodeMirror and used the useCodeMirror
hook as a basis.
from react-textarea-code-editor.
You'll find easy reproduction steps in the README file of https://github.com/activenode-bugs/uiw-react-textarea-code-editor-jest
from react-textarea-code-editor.
dist
The ones in dist belong toUMD
,UMD
builds can be used directly in the browser via a <script> tag. Examplecjs
CommonJS: CommonJS builds are intended for use with older bundlers like browserify or webpack 1. The default file for these bundlers (pkg.main) is the Runtime only CommonJS buildesm
ES Module: ES module builds are intended for use with modern bundlers like webpack 2 or rollup. The default file for these bundlers (pkg.module) is the Runtime only ES Module build
from react-textarea-code-editor.
Thanks for clarifying the difference. Can you imagine why the error of import
appears even though commonjs
shouldn't lead to that? Like this is really confusing. I've tried it in at least 5 different setups, with and without TypeScript, with and without nextjs and it's always the exact same thing.
Once you are using your library anywhere with jest (no matter if just jest, babel-jest
or ts-jest
or both) it will always lead to this exact problem that you face when you run the related repo.
from react-textarea-code-editor.
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.
@activenode
from react-textarea-code-editor.
Okay so rehype
package only contains ESM
and that is why your library (which has rehype
as dependency) will not work in this context as rehype
doesn't have the cjs
version apparently.
from react-textarea-code-editor.
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 rehype
. Your CJS version essentially mixes with ESM
from react-textarea-code-editor.
So I can see 3 possible options here:
- Remove CJS support in your library (as it won't work together with rehype)
- Pre-compile rehype with the CJS version for the
cjs
dist - Use a different package than
rehype
If you choose option 1 that's completely fine, I just need the transparency so that I can switch back to our old react-simple-code-editor
Thank you so much!
from react-textarea-code-editor.
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.
from react-textarea-code-editor.
Thanks for the hints.
from react-textarea-code-editor.
https://github.com/jaywcjlove/markdown-to-html-cli
This is also a solution.
jest test cases are separated from pkg.
from react-textarea-code-editor.
Thank you, I will look into the suggestions.
from react-textarea-code-editor.
Hey @activenode which suggestion did you end up going with?
from react-textarea-code-editor.
I managed to fix this issue by changing the import.
Instead of
import CodeEditor from '@uiw/react-textarea-code-editor';
used:
import CodeEditor from '@uiw/react-textarea-code-editor/esm';
from react-textarea-code-editor.
Related Issues (20)
- How To Display Programming Language Select Button HOT 1
- bundle size HOT 2
- how to do command enter and preventing enter from being sent to code editor? HOT 7
- Auto comment selection HOT 2
- Is `font-family: inherit;` in `.w-tc-editor` required? HOT 2
- JSON Highlighting of Value the same as the Name when a string HOT 2
- [Fix] Shift+Tab on single line removes starting tab HOT 3
- Add the ability to highlight individual lines HOT 2
- Pressing the tab key on a readonly textarea causes a tab in the value HOT 1
- Disable prop HOT 2
- Unable to access ref on CodeEditor using NextJS dynamic HOT 2
- chinese input error HOT 2
- [Feature Request] CSV support HOT 3
- CTRL + Z | Undo HOT 2
- gray color on text highlight HOT 4
- Can I show line numbers ? HOT 1
- Can I show line numbers ? HOT 2
- How to import `TextareaCodeEditorProps` in v3 +? HOT 2
- Module not found: Can't resolve 'devlop' HOT 3
- more customisable padding HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-textarea-code-editor.