rehype-pretty-code
rehype-pretty-code copied to clipboard
Yarn monorepo ESM issue
I'm working on a project that's a yarn monorepo, with one package being an app that consumes rehype-pretty-code
.
I had an issue with importing (ESM/CJS rubbish) that I was able to solve with a patch, but want to check that it might be something that could be brought into the actual package.
When importing the package I would get an error no exports main found for .../node_modules/rehype-pretty-code/package.json
.
I believe that the "most correct" approach is to ensure that my package.json has type: module
, however, because this is a yarn monorepo that is not possible as it causes a plethora of other issues in other places.
I was able to get around the issue by patching in an additional line to the exports field in the package.json for rhype-pretty-code
"require": "./dist/index.js"
I believe that what I have patched is just adding CJS import support to the package, so I want to be very clear that at no point am I using require
, I'm only writing ESM imports. I am well aware that the docs specify that "only ESM imports are supported".
So the reason I raise this issue, I think that it would be good if this line was added to the project so that others like me in future don't have to spend time on this exact issue. I am NOT suggesting that the package should support CJS imports. I am more suggesting widening the pit of success. Maybe there's very few people that will encounter this issue, but I would be surprised if I'm the only one.
If it sounds like an acceptable change I am happy to contribute!
do you have a link to your repo?
hi @o-az unfortunately it's not open source so I can't share it, I can have a crack at a reproduction although I don't think this is a very urgent issue.
Apologies for the delayed reply I don't often raise issues and did not check my GH notifications
No problem. I'm going to close this but feel free to create a new issue when you have a repro.