Bug: Code Editor + Jest not working
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- build-system, frontend, testing-qa
Research direction
Start by running npm i and yarn jest in the linked reproduction repository to confirm the import error. Then inspect the package metadata and the esm, cjs, and dist/editor.js entry points, including the main field, and compare how Jest resolves each one. Done means the library can be imported under Jest without moduleNameMapper, with the entry-point behavior documented or corrected.
Written by the indexing model from the issue text.
Description
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 using cjs - 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 run yarn 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 the rehype library with an import 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 a dist folder. If you use jest with moduleNameMapper and then map @uiw/react-textarea-code-editor to @uiw/react-textarea-code-editor/dist/editor.js it will work / run.
moduleNameMapper: {
// if you use the following, it will work
// '@uiw/react-textarea-code-editor':
// '<rootDir>/node_modules/@uiw/react-textarea-code-editor/dist/editor.js',
},
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 AND dist (can you clarify the differentiation?) and why does dist/editor.js work but cjs 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!
- Dominant language
- TypeScript
- Stars
- 575
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uiwjs/react-textarea-code-editor
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
uiwjs/react-textarea-code-editor#186 · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
uiwjs/react-textarea-code-editor#183 · 1 comment · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
uiwjs/react-textarea-code-editor#182 · 3 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
uiwjs/react-textarea-code-editor#181 · 4 comments · 12 reactions ·
All issues in uiwjs/react-textarea-code-editor
Similar issues
-
area/core status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
google-gemini/gemini-cli#29602 ·
Maintainers usually reply within 1 day
-
area: backend enhancement priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
snapotter-hq/SnapOtter#1879 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Tencent/BrowserSkill#390 ·
Maintainers usually reply within 1 day
-
good first issue status: needs triaging type: bug version: 2.0
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
medusajs/medusa#17094 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day