tocbot: Added ESM version breaks storybook build
Hello, we are using Storybook in our library, which has tocbot as a dependency. After minor upgrade of Storybook, it no longer builds. Investigation revealed that after adding ESM version, storybook build in our library was broken:
Error: No "exports" main defined in ./node_modules/tocbot/package.json
Storybook version is 7.6.17, which has tocbot as a dependency at ^4.20.0.
Workaround for now is to override tocbot version.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 26 (9 by maintainers)
@zhangzhenxi0316
tocbot@4.27.5is published with that change. Let me know if that helps. Thanks!Hi @Josh-Walker-GM, I pushed a fix to add those exports back, can you try
tocbot@4.27.4?image hi @tscanlin , I encountered this problem as shown above
i think u need set default import config in package.json like this
After I manually added default exports, the build went normally.
The strange thing is that whether I export the esmodule product or the common js product, it can be built successfully in the end.
Awesome, glad to hear! I’ve merged the PR and kicked off a release.
4.27.17has the type: ‘module’ change.Thanks for your help validating this @dchambers! 👍
@tscanlin, thanks so much for the rapid response on this. I struggled a little grabbing from Git, and so this is the config I ended up using:
where the test are successfully passing ✅
Hi @tscanlin 👋, thanks so much for you help with this issue BTW.
We don’t directly import from
tocbot, but we instead have a component which imports from@storybook/blocks, and the error occurs when running the unit tests for that component in a version of Jest configured to use Jest’s ESM support:This is the error message we see:
I’ve personally seen the ‘Cannot use import statement outside a module’ error quite a bit when using Node.js directly, and so I’d imagine you’d see this error if you were to create a Node.js project with
"type": "module",and have it import the builttocbot/index.jsfile.For context, we use Jest’s ESM support because it allows to verify that the hybrid ESM/CJS modules that we export will actually work when consumed from various ESM toolchains. We use quite a few tools in our toolchain, and one observation I’ve had is that different tools have different levels of strictness over which transgressions from the ESM standards that they’ll accept, where Jest’s ESM tooling (which is based on Node.js’s ESM support) seems to be one of the strictest.
I can confirm, that the latest version works for me too 😃 thanks for so fast fixes!
There should be no need for this, as they have it defined as ^4.20. so it is upgraded to latest 4.2* version automatically (at least with npm)
With Bun, you can override until Storybook updates:
Make sure to remove node_modules and reinstall
@tscanlin It looks like the latest version resolves our issue. Thanks for the resolution!
@tscanlin Here is an example that demonstrates the issue in storybook: https://stackblitz.com/edit/github-7s5dz5?file=.storybook%2Fmain.ts The @storybook/blocks is the storybook add-on in which we are seeing the issue.
@tscanlin
hi~,please check package.json config, The default parameter needs to be at the bottom of the export configuration
thanks
@tscanlin It’s used by Storybook so I’m not too sure. But
tocbot@4.27.5solved the issue 🥳. Thank you!Looks like that’s fixed it for us. Thanks for the incredibly quick turn around!