Skip to content

Commit

Permalink
Merge pull request #17486 from storybookjs/revert-17361-revert-16727-…
Browse files Browse the repository at this point in the history
…fix/require-is-undefined

Core: Rename `generated-stories-entry` to `cjs` extension so require works
  • Loading branch information
shilman committed Feb 11, 2022
2 parents 2eac53a + 23c05dd commit 0dc3091
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Expand Up @@ -128,6 +128,8 @@ export default async (options: Options & Record<string, any>): Promise<Configura
const clientApi = storybookPaths['@storybook/client-api'];
const clientLogger = storybookPaths['@storybook/client-logger'];

// NOTE: although this file is also from the `dist/cjs` directory, it is actually a ESM
// file, see https://github.com/storybookjs/storybook/pull/16727#issuecomment-986485173
virtualModuleMapping[`${configFilename}-generated-config-entry.js`] = interpolate(
entryTemplate,
{
Expand All @@ -142,7 +144,10 @@ export default async (options: Options & Record<string, any>): Promise<Configura
const storyTemplate = await readTemplate(
path.join(__dirname, 'virtualModuleStory.template.js')
);
const storiesFilename = path.resolve(path.join(workingDir, `generated-stories-entry.js`));
// NOTE: this file has a `.cjs` extension as it is a CJS file (from `dist/cjs`) and runs
// in the user's webpack mode, which may be strict about the use of require/import.
// See https://github.com/storybookjs/storybook/issues/14877
const storiesFilename = path.resolve(path.join(workingDir, `generated-stories-entry.cjs`));
virtualModuleMapping[storiesFilename] = interpolate(storyTemplate, { frameworkImportPath })
// Make sure we also replace quotes for this one
.replace("'{{stories}}'", stories.map(toRequireContextString).join(','));
Expand Down

0 comments on commit 0dc3091

Please sign in to comment.