Incorrect entry point for cjs
Issue description
The package.json file specifies "type": "module", but entry point uses commonjs (require Syntax).
refer to: https://nodejs.org/api/packages.html#type
This causes errors when you try to test with vitest. You will get "require() of ES Module ... not supported."
Expected Behavior
The package.json should state "type": "commonjs" or change ./dist/tocbot.js file to ./dist/tocbot.cjs
Environment
Library version: v4.28.2
Yes still seems to be an issue with 4.28.2, and is related to https://github.com/tscanlin/tocbot/issues/340.
I've just had to downgrade to 4.27.16 again.
Hey, sorry for the late reply, I was out of town last week.
Can you help me figure out how to reproduce this issue?
I've tried building a project with the lastest version of vite and adding tocbot to it but I do not see any build errors (yarn create vite my-app --template react). I also will note that I did change the project type from module to commonjs, but maybe I'm missing something else.
A reproduction of this issue would be very helpful. Thanks!
Yeah no worries, I just tried to reproduce it again and can't, not sure what changed, but if it crops up again I'll try make a reproduction for it, but otherwise seems fine now 🤷♂️
Ok cool, thanks for checking again! I'll keep this open for a bit in case anyone else is running into this and will plan to close in a couple weeks if I don't hear anything. But feel free to ping back here and I'm happy to look into this if it's still an issue.
Also, fwiw I tested the new versions in some old commonjs repos that I had and it worked fine, but I'm not going to rule out that there could still be issues with other types of repos.
Thank you @jcwillox!! :)
Hi @tscanlin sorry for missing your reply.
I can still reproduce the bug with 4.28.2, but override tocbot version as jcwillox suggested works fine.
Instead of using tocbot directly in my project, I used storybook 7.6.16 in my dependencies, which in turn depends on tocbot 4.28.2. Hopefully this thread will help you reproduce the bug.
The exports.require field of the tocbot package specifies the use of the ". /dist/tocbot.js" file. Since the project type is defined as module, ". /dist/tocbot.js" is an implicit". /dist/tocbot.mjs", the error "require() of ES Module ...not supported" will appear. Need to explicitly ". /dist/tocbot.js" file is a commonjs file as ". /dist/tocbot.cjs".
Thanks a lot :)
Thanks for describing the issue more! I've put up this PR, hopefully it solves this: https://github.com/tscanlin/tocbot/pull/353/files
Do you have a repo you could test this in?
Yeah, works fine now!
Glad to hear that worked! Thanks for verifying! This is merged and published in [email protected]