Coder Social home page Coder Social logo

Comments (15)

activenode avatar activenode commented on July 2, 2024 1

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.

activenode avatar activenode commented on July 2, 2024 1

@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:
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.

activenode avatar activenode commented on July 2, 2024

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.

jaywcjlove avatar jaywcjlove commented on July 2, 2024

@activenode

  • dist The ones in dist belong to UMD, UMD builds can be used directly in the browser via a <script> tag. Example
  • cjs 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 build
  • esm 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.

activenode avatar activenode commented on July 2, 2024

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.

jaywcjlove avatar jaywcjlove commented on July 2, 2024

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.

activenode avatar activenode commented on July 2, 2024

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.

image

from react-textarea-code-editor.

activenode avatar activenode commented on July 2, 2024

The official documentation confirms that

image

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.

activenode avatar activenode commented on July 2, 2024

So I can see 3 possible options here:

  1. Remove CJS support in your library (as it won't work together with rehype)
  2. Pre-compile rehype with the CJS version for the cjs dist
  3. 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.

jaywcjlove avatar jaywcjlove commented on July 2, 2024

"transformIgnorePatterns": [
"<rootDir>/node_modules/?!(.*)"
],

Can be used together, depending on the build tool and your code. Iteration takes a while and is not that aggressive at the moment.

@activenode

It has some ways to do compatibility.

image

from react-textarea-code-editor.

activenode avatar activenode commented on July 2, 2024

Thanks for the hints.

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 2, 2024

https://github.com/jaywcjlove/markdown-to-html-cli

This is also a solution.
jest test cases are separated from pkg.

@activenode

from react-textarea-code-editor.

activenode avatar activenode commented on July 2, 2024

Thank you, I will look into the suggestions.

from react-textarea-code-editor.

simon-v-swyftx avatar simon-v-swyftx commented on July 2, 2024

Hey @activenode which suggestion did you end up going with?

from react-textarea-code-editor.

CiprianDraghici avatar CiprianDraghici commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.