Skip to content
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

docs: add next-dynamic-access-named-export codemod #71012

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add next-dynamic-access-named-export codemod
  • Loading branch information
devjiwonchoi committed Oct 9, 2024
commit 38f46795562c706dbea5f650660f4a7358ec2749
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,46 @@ export function GET(req: NextRequest) {
}
```

#### Migrate `next/dynamic` to access named exports

##### `next-dynamic-access-named-export`

```bash filename="Terminal"
npx @next/codemod@latest next-dynamic-access-named-export .
```

This codemod transforms dynamic imports using `next/dynamic` to ensure they return an object with a `default` property when accessing named exports. This aligns the behavior with `React.lazy` and addresses issues with accessing named exports from client components in server components.

For example:

```js
import dynamic from 'next/dynamic'

const ComponentA = dynamic(() =>
import('../components/a').then((mod) => mod.default)
)

const ComponentB = dynamic(() =>
import('../components/b').then((mod) => mod.ComponentB)
)
```

Transforms into:

```js
import dynamic from 'next/dynamic'

const ComponentA = dynamic(() =>
import('../components/a').then((mod) => ({ default: mod.default }))
)

const ComponentB = dynamic(() =>
import('../components/b').then((mod) => ({ default: mod.ComponentB }))
)
```

> **Good to know**: This codemod only affects dynamic imports using `next/dynamic` and access named exports.

### 14.0

#### Migrate `ImageResponse` imports
Expand Down
Loading