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

[Bug]: Error [ERR_REQUIRE_ESM]: require() of ES Module at @storybook/addon-docs #29467

Open
mistic opened this issue Oct 29, 2024 · 4 comments · May be fixed by #30151
Open

[Bug]: Error [ERR_REQUIRE_ESM]: require() of ES Module at @storybook/addon-docs #29467

mistic opened this issue Oct 29, 2024 · 4 comments · May be fixed by #30151

Comments

@mistic
Copy link

mistic commented Oct 29, 2024

Describe the bug

We are trying to upgrade the internal usage of storybooks from v6 into v8 and we are now facing an issue that was introduced by #25615.

We launch the storybook builds through a Node.js script that uses the buildStandalone function from @storybook/react/standalone. During the node resolution phase we got the following error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/rehype-external-links/index.js from /node_modules/@storybook/addon-docs/dist/preset.js not supported.
      Instead change the require of index.js in /node_modules/@storybook/addon-docs/dist/preset.js to a dynamic import() which is available in all CommonJS modules.
          at Object.newLoader [as .js] 

The cause seems to be related with the fact that the cjs build of @storybook/addon-docs is requiring an ESM module. It feels to me this PR should be reverted until a better alternative to replace those packages is found or the interop for esm and require is better supported on node (initial interop was released on node v22 but has limitations and it is still experimental).

\cc @JReinhold

Reproduction link

elastic/kibana#195148

Reproduction steps

  1. Checkout the PR
  2. yarn kbn bootstrap && yarn storybook esql_editor

System

Storybook v8

Additional context

No response

@valentinpalkovic
Copy link
Contributor

Hi @mistic

This PR might fix your issue: #29544
Do you mind trying it out with the following canary release?
npx [email protected] upgrade

@Ikuni17
Copy link

Ikuni17 commented Nov 5, 2024

Hi @valentinpalkovic, I'm on the same team as @mistic.

Thanks for the PR, the canary release is working for rehype packages now. We're seeing a similar error for react-docgen while using addon-docs:

Module build failed: Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/react-docgen/dist/main.js from /node_modules/@storybook/preset-react-webpack/dist/loaders/react-docgen-loader.js not supported.
Instead change the require of main.js in /node_modules/@storybook/preset-react-webpack/dist/loaders/react-docgen-loader.js to a dynamic import() which is available in all CommonJS modules.

@JReinhold
Copy link
Contributor

I believe this is happening because you're not using the Storybook CLI to build your Storybook, but instead build from @storybook/core-server directly. Therefore some module resolutions and loaders aren't set up properly.

That is not a public API and we don't support that pattern in any way.

I'm fine with trying to fix react-docgen here too, but I can't promise we won't "regress" on this in the future, because this type of usage is definitely not something we test for.

@tobiasdiez
Copy link
Contributor

@JReinhold would it be possible to make this API official and public, and add tests for it as well? The Nuxt module also relies on it, and we experience similar issues: nuxt-modules/storybook#825

@tobiasdiez tobiasdiez linked a pull request Dec 28, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants