diff --git a/code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts b/code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
index 669a836e65ea..c90a807c4044 100644
--- a/code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
+++ b/code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
@@ -74,7 +74,6 @@ test('convert story re-definition', () => {
expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
- import { Primary } from './Foobar.stories';
import * as FoobarStories from './Foobar_.stories';
@@ -242,7 +241,6 @@ test('extract esm into csf head code', () => {
expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
- import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
# hello
@@ -406,7 +404,6 @@ test('duplicate story name', () => {
expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
- import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
@@ -451,7 +448,6 @@ test('story name equals component name', () => {
expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
- import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
@@ -494,7 +490,6 @@ test('kebab case file name', () => {
expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
- import { Kebab } from './my-component/some-kebab-case';
import * as SomeKebabCaseStories from './some-kebab-case.stories';
diff --git a/code/lib/codemod/src/transforms/mdx-to-csf.ts b/code/lib/codemod/src/transforms/mdx-to-csf.ts
index 06cb563bd333..01e42148cc01 100644
--- a/code/lib/codemod/src/transforms/mdx-to-csf.ts
+++ b/code/lib/codemod/src/transforms/mdx-to-csf.ts
@@ -347,6 +347,11 @@ function cleanUpMdx(root: Root): void {
file.path.traverse({
ExportDeclaration: (path) => path.remove(),
+ ImportDeclaration: (path) => {
+ if (path.node.source.value !== '@storybook/blocks') {
+ path.remove();
+ }
+ },
});
const code = recast.print(file.path.node).code.trim();
if (code === '') {