react-doctor/no-dynamic-import-path
Use a string-literal path: `import('./feature/heavy.js')` so the bundler can split this chunk
- Category: Bundle Size
- Severity: warn
- Source:
oxlint-plugin-react-doctor - Framework: global
- Enabled when: always
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Confirm an ImportExpression whose source is neither a string Literal nor a zero-expression TemplateLiteral, OR a require() CallExpression whose first argument has the same property. The rule fires on variables, string concatenation, and interpolated templates like ./locales/${lang} that webpack, Rollup, and esbuild cannot statically trace into a separate chunk.
Fix prompt
Use this once validation confirms the diagnostic is real.
Replace the computed path with a literal — typically a switch or object map of every known value to its own import("./locales/en.js") call, or webpack's magic-comment form import(/* webpackChunkName: "locales" */ ./locales/${lang}.js) where the variable part is constrained. See https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import
Related rules
More Bundle Size rules from the rules reference:
react-doctor/no-full-lodash-import: Import the specific function: `import debounce from 'lodash/debounce'` — saves ~70kbreact-doctor/no-moment: Replace with `import { format } from 'date-fns'` (tree-shakeable) or `import dayjs from 'dayjs'` (2kb)react-doctor/no-undeferred-third-party: Use `next/script` with `strategy="lazyOnload"` or add the `defer` attributereact-doctor/prefer-dynamic-import: Use `const Component = dynamic(() => import('library'), { ssr: false })` from next/dynamic or React.lazy()react-doctor/use-lazy-motion: Use `import { LazyMotion, m } from "framer-motion"` with `domAnimation` features — saves ~30kb