Closed aliceHendicott closed 2 years ago
I ran into the same problem. But I tried your proposed changes and got this:
Error: Cannot find module '/home/chris/files/web/homepage/node_modules/gatsby-remark-table-of-contents/di
st/gatsby-remark-table-of-contents.cjs.js'. Please verify that the package.json has a valid "main" entry
at tryPackage (node:internal/modules/cjs/loader:353:19)
at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.resolve
(/home/chris/files/web/homepage/node_modules/v8-compile-cache/v8-compile-cache.js:164:23)
at map
(/home/chris/files/web/homepage/node_modules/gatsby/src/bootstrap/load-plugins/validate.ts:232:48)
at Array.map (<anonymous>)
at /home/chris/files/web/homepage/node_modules/gatsby/src/bootstrap/load-plugins/validate.ts:225:35
at Object.validate (/home/chris/files/web/homepage/node_modules/joi/lib/types/any.js:47:28)
at Object.internals.rules (/home/chris/files/web/homepage/node_modules/joi/lib/validator.js:397:33)
at Object.exports.validate (/home/chris/files/web/homepage/node_modules/joi/lib/validator.js:353:22)
at internals.Base.$_validate (/home/chris/files/web/homepage/node_modules/joi/lib/base.js:773:26)
at Object.validate (/home/chris/files/web/homepage/node_modules/joi/lib/types/keys.js:108:45)
at Object.exports.validate (/home/chris/files/web/homepage/node_modules/joi/lib/validator.js:328:26)
at Object.internals.entry (/home/chris/files/web/homepage/node_modules/joi/lib/validator.js:145:28)
at Object.exports.entryAsync (/home/chris/files/web/homepage/node_modules/joi/lib/validator.js:58:30)
at internals.Base.validateAsync (/home/chris/files/web/homepage/node_modules/joi/lib/base.js:553:26)
{
code: 'MODULE_NOT_FOUND',
path: '/home/chris/files/web/homepage/node_modules/gatsby-remark-table-of-contents/package.json',
requestPath: '/home/chris/files/web/homepage/node_modules/gatsby-remark-table-of-contents'
}
I'm very inexperienced with the JavaScript world, so my way of installing your version yarn remove git+https://github.com/aliceHendicott/gatsby-remark-table-of-contents
might be flawed.
Anyway, I think it makes sense to move this to a PR.
@christopher-besch I've done up a PR with this change so hopefully the maintainers get to this soon.
You won't be able to install my fork as I haven't published it anywhere. If you are looking for a workaround for the time being, to fix the issue in my Gatsby project, I have used patch-package
to change the export in the gatsby-remark-table-of-contents
main .cjs
file from default export
to module.exports
and it has resolved the issue for now.
Thank you @aliceHendicott for the investigation and your work! I merged your PR to not let you wait any longer and published a new major release in npm. With Version 2.0.0
you should get your suggested export. Since I didn't find the time to test it properly, I'm super happy if you can test it in your project.
@christopher-besch also thank you for your report. Please try version 2.0.0
and let us know if you were successful. If you need help how to update your package to the new version, let us know.
Thanks @signalwerk for getting to this so quickly!
I've just tested version 2.0.0
in my gatsby project and it is working perfectly!
I've tested it as well and everything works as it should. This issue can be closed. Thanks a lot, you two!
@aliceHendicott @christopher-besch thank you for testing and the feedback!
After upgrading Gatsby to v4, using
gatsby-remark-table-of-contents
no longer works when used withgatsby-plugin-mdx
(the same may be true for other ways of using this package but I have not tried it withgatsby-transformer-remark
).Basically what's happening is, the
gatsby-plugin-mdx
tries to importgatsby-remark-table-of-contents
but because it usesexport default
instead ofmodule.exports
, it thinks the export is anobject
rather than afunction
and therefore doesn't run the transform.After playing around with the config, a simple solution to this problem is to alter the rollup output config, specifically the
output.exports
option fromnamed
todefault
- https://github.com/aliceHendicott/gatsby-remark-table-of-contents/commit/b5b6b20444acb322ba17e1ea30b93c0468505514.Do you see any issues with adding this change? Happy to do up a PR if it makes sense to include this change.