diff --git a/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts b/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts index 6c7b548235f2..1f896ed5e8e8 100644 --- a/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts +++ b/code/lib/cli/src/automigrate/fixes/missing-babelrc.test.ts @@ -75,6 +75,19 @@ describe('missing-babelrc fix', () => { await expect(check({ packageJson })).resolves.toBeNull(); }); + it('skips when using CRA preset', async () => { + const packageJson = { + devDependencies: { + '@storybook/react': '^7.0.0', + '@storybook/react-webpack5': '^7.0.0', + }, + }; + + await expect( + check({ packageJson, main: { addons: ['@storybook/preset-create-react-app'] } }) + ).resolves.toBeNull(); + }); + it('prompts when babelrc file is missing and framework does not provide babel config', async () => { const packageJson = { devDependencies: { diff --git a/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts b/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts index 7fda44e0a0cb..6ef7fa56202f 100644 --- a/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts +++ b/code/lib/cli/src/automigrate/fixes/missing-babelrc.ts @@ -57,7 +57,14 @@ export const missingBabelRc: Fix = { const frameworkPackage = typeof frameworkField === 'string' ? frameworkField : frameworkField?.name; - if (frameworksThatNeedBabelConfig.includes(frameworkPackage)) { + const addons: any[] = main.getFieldValue(['addons']) || []; + + const hasCraPreset = addons.find((addon) => { + const name = typeof addon === 'string' ? addon : addon.name; + return name === '@storybook/preset-create-react-app'; + }); + + if (frameworksThatNeedBabelConfig.includes(frameworkPackage) && !hasCraPreset) { const config = await loadPartialConfigAsync({ babelrc: true, });