Next Dynamic doesn't work as expected with swcTransform
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, nextjs, react
- Domain
- build-system, frontend
Research direction
Start with the linked dynamic-import-issue reproduction: run yarn install and yarn dev, then compare forceSwcTransforms in next.config.js with and without babel.config.js. Inspect the dynamic import of components/Header and verify that the Hello chunk loads only after clicking Show Header under SWC, matching the existing Babel behavior.
Written by the indexing model from the issue text.
Description
Link to the code that reproduces this issue
https://github.com/milap1296/dynamic-import-issue
To Reproduce
- yarn install.
- yarn dev.
- Set
forceSwcTransforms: truein next.config.js. - See that the dynamically loaded component is preloaded when swc transpilation is enabled.
- It is not preloaded when
forceSwcTransforms: falseis set and works as expected with babel transpilation.
Current vs. Expected behavior
Current Behavior
Click on the Show Header button and the chunk corresponding to Hello should only be rendered then. It works as expected when forceSwcTransforms is false but when forceSwcTransforms is true, it preloads the Hello even before we click the Show Header button.
The underlying issue here is with this particular code - dynamic(import('../components/Header'), it works as expected with swc if I replace it with dynamic(() => import('../components/Header'), but what should be the ideal behavior because there are many instances of such in my app.
Expected Behavior
Lazy Loading should work as expected when forceSwcTransforms is true. This also doesn't work when the babel.config.js file is not present and we don't have any experimental configuration as well.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000
Binaries:
Node: 18.18.2
npm: 9.8.1
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 14.0.4
eslint-config-next: 14.0.4
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config: {
swcMinify: true,
reactStrictMode: true
}
Which area(s) are affected? (Select all that apply)
SWC transpilation
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
No response
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 334
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel/next.js
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Image (next/image)
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Loading UI and Streaming
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100