rehype-pretty-code icon indicating copy to clipboard operation
rehype-pretty-code copied to clipboard

Yarn monorepo ESM issue

Open caffeinated-nick opened this issue 9 months ago • 1 comments

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!

caffeinated-nick avatar May 09 '24 23:05 caffeinated-nick

do you have a link to your repo?

o-az avatar May 14 '24 06:05 o-az

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

caffeinated-nick avatar Jun 05 '24 06:06 caffeinated-nick

No problem. I'm going to close this but feel free to create a new issue when you have a repro.

o-az avatar Jun 06 '24 12:06 o-az