Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of rehype-parse causes CommonJS builds to fail #345

Closed
strmer15 opened this issue Jul 24, 2024 · 7 comments
Closed

Use of rehype-parse causes CommonJS builds to fail #345

strmer15 opened this issue Jul 24, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@strmer15
Copy link

Versions

  • @prismicio/client: 7.7.4
  • node: 20.15.1

Reproduction

Get the latest version of @prismicio/client and use it in a CommonJS build with Webpack.

Additional Details

Steps to reproduce

Use @prismicio/client 7.7.x in a CommonJS build with Webpack.

What is expected?

I can use @prismicio/client in a CommonJS Webpack build without any errors.

What is actually happening?

It's throwing ERR_REQUIRE_ESM when trying to load rehype-parse. The rehype-parse package is ESM only, so by including it this package has essentially become ESM only.

/home/cplummer/work/beethoven/node_modules/.pnpm/@[email protected]/node_modules/@prismicio/client/dist/helpers/unstable_htmlAsRichText.cjs:121
undefined
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/cplummer/work/beethoven/node_modules/.pnpm/[email protected]/node_modules/rehype-parse/index.js from /home/cplummer/work/beethoven/node_modules/.pnpm/@[email protected]/node_modules/@prismicio/client/dist/helpers/unstable_htmlAsRichText.cjs not supported.
Instead change the require of index.js in /home/cplummer/work/beethoven/node_modules/.pnpm/@[email protected]/node_modules/@prismicio/client/dist/helpers/unstable_htmlAsRichText.cjs to a dynamic import() which is available in all CommonJS modules.
    at Object.newLoader [as .js] (/home/cplummer/work/beethoven/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:121:7)
    at Module.<anonymous> (/home/cplummer/work/beethoven/node_modules/.pnpm/@[email protected]/node_modules/@prismicio/client/dist/helpers/unstable_htmlAsRichText.cjs:3:21)
    at Object.newLoader [as .js] (/home/cplummer/work/beethoven/node_modules/.pnpm/[email protected]/node_modules/pirates/lib/index.js:121:7) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.15.1
@strmer15 strmer15 added the bug Something isn't working label Jul 24, 2024
Copy link

This issue has been labeled as a bug since it was created using the 🚨 Bug Report Template.

Hi there, thank you so much for the report!

Following our Maintenance Process, we will review your bug report and get back to you next Wednesday. To ensure a smooth review of your issue and avoid unnecessary delays, please make sure your issue includes the following:

  • Information about your environment and packages you use (Node.js version, package names and their versions, etc.)
    Feel free to attach a copy of your package.json file.
  • Any troubleshooting steps you already went through
  • A minimal reproduction of the issue, and/or instructions on how to reproduce it

If you have identified the cause of the bug described in your report and know how to fix it, you're more than welcome to open a pull request addressing it. Check out our quick start guide for a simple contribution process.

If you think your issue is a question (not a bug) and would like quicker support, please close this issue and forward it to an appropriate section on our community forum: https://community.prismic.io

- The Prismic Open-Source Team

@lihbr
Copy link
Member

lihbr commented Jul 25, 2024

Hi @strmer15, thanks for contributing and bringing this issue to our attention.

I'm curious if you can share more about your webpack setup? Which framework you're using, meta-framework if any, etc.

We'll release a fix for this tomorrow, in the meantime, pinning @prismicio/client to ~7.6.0 should keep you rolling.

Thank you for your understanding 🙏

@strmer15
Copy link
Author

Thanks for getting back to me! We're using Webpack 5 and Typescript 5.5 with React 18, just a custom config that has swc-loader to transform TS / JS along with some other typical CSS / SVG / GraphQL loaders for bundling. It also uses SSR to build pages that are SEO compatible, so there's both a server and client bundle to support that. I don't think I can share the full config, but let me know if you want other info about how we're doing this.

@lihbr
Copy link
Member

lihbr commented Jul 26, 2024

Hey @strmer15, just keeping you in the loop.

We opened #346 to address this issue. It'll probably be published between today and Monday ☺️

@lihbr
Copy link
Member

lihbr commented Jul 29, 2024

Hey @strmer15, just letting you know we're aligning on a strategy to fix this issue durably so we might need a few extra days to release this fix (I'm expecting Wednesday, definitely this week) to prevent confusion and additional back-and-forth and between the solutions we're envisaging (non-exhaustively: inlining ESM-only dependencies to CJS, exporting the new utilities we introduced to a dedicated package)

Is it alright for you to remain on ~7.6.0 until then?

@strmer15
Copy link
Author

Hey @lihbr ! No problem, there's no rush here on our part - we're good being on 7.6.0 for a while. Definitely make sure you take all the time you need to come up with the right fix, thanks!

@lihbr
Copy link
Member

lihbr commented Aug 1, 2024

Hi @strmer15, this should be fixed with @prismicio/client latest release.

npm install @prismicio/client@latest

Thanks for your patience! 🙏 Feel free to reopen if you still experience the same trouble.

@lihbr lihbr closed this as completed Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants