-
Notifications
You must be signed in to change notification settings - Fork 8
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
Broken when dev with type: module #22
Comments
I can confirm the same issue on my side. Trying to migrate from webpack to rsbuild and using type: module. I also use module federation and the motivation to move to rsbuild is of course speed :) |
As a temporary workaround, I can use Add storybook-builder-rsbuild as dev dependency (That helps to find the package in node_modules) diff --git a/templates/virtualModuleModernEntry.js.handlebars b/templates/virtualModuleModernEntry.js.handlebars
index 1224d3d015df76df07e8074d9328ae19174959ee..e5014d3741dfe116ccf0fae9273457966bf3dd71 100644
--- a/templates/virtualModuleModernEntry.js.handlebars
+++ b/templates/virtualModuleModernEntry.js.handlebars
@@ -5,8 +5,8 @@ import { createBrowserChannel } from '@storybook/channels';
import { importFn } from './{{storiesFilename}}';
-const getProjectAnnotations = () =>
- composeConfigs([{{#each previewAnnotations}}require('{{this}}'),{{/each}}]);
+const getProjectAnnotations = async () =>
+ composeConfigs([{{#each previewAnnotations}}await import('{{this}}'),{{/each}}]);
const channel = createBrowserChannel({ page: 'preview' });
addons.setChannel(channel); I think the diff clearly illustrates the cause of the bug, but I don't know how the module type could be correctly pass to the template. If there are any suggestions I can offer a fix. |
All right, I don't know how to load the package.json then pass to |
I took a look into the code and took a test locally. Using async writing work fine for const getProjectAnnotations = async () => {
const configs = await Promise.all([{{#each previewAnnotations}}import('{{this}}'),{{/each}}])
return composeConfigs(configs);
} |
|
Webpack + babel example (no issue): Hope it helps. |
Reproduction
https://github.com/yf-yang/rsbuild-storybook-esm
Note: I added
type: module
in the package.json, others are remaining the same with the exampleError
Execute
pnpm storybook
The server starts successfully, then each component throws "ReferenceError: require is not defined"
Additional resouces
Seems there is a similar old bug storybookjs/storybook#14877
The text was updated successfully, but these errors were encountered: