From cde08674427f005aafc63a4cec7a216217974f53 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Sun, 2 Jan 2022 11:32:12 +0200 Subject: [PATCH] Fix require used in virtualModuleModernEntry template When **package.json** contains `{ "type": "module" }`, the build fails with `Uncaught ReferenceError: require is not defined`. Fixes https://github.com/storybookjs/storybook/issues/14877 We'd still need to ensure that all the imported files have their extension specified (`.js`). --- .../src/preview/virtualModuleModernEntry.js.handlebars | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/builder-webpack5/src/preview/virtualModuleModernEntry.js.handlebars b/lib/builder-webpack5/src/preview/virtualModuleModernEntry.js.handlebars index 514bc546821d..5af12bb88f43 100644 --- a/lib/builder-webpack5/src/preview/virtualModuleModernEntry.js.handlebars +++ b/lib/builder-webpack5/src/preview/virtualModuleModernEntry.js.handlebars @@ -11,8 +11,8 @@ import { importFn } from './{{storiesFilename}}'; const { SERVER_CHANNEL_URL } = global; -const getProjectAnnotations = () => - composeConfigs([{{#each configs}}require('{{this}}'),{{/each}}]); +const getProjectAnnotations = async () => + composeConfigs(await Promise.all([{{#each configs}}import('{{this}}'),{{/each}}])); const channel = createPostMessageChannel({ page: 'preview' }); addons.setChannel(channel); @@ -42,4 +42,4 @@ if (module.hot) { // getProjectAnnotations has changed so we need to patch the new one in preview.onGetProjectAnnotationsChanged({ getProjectAnnotations }); }); -} \ No newline at end of file +}