{"record":{"id":"79a1285c19e85863","repo":"swc-project/swc","slug":"unimplemented-dynamic-code-splitting","errorCode":null,"errorMessage":"unimplemented: dynamic code splitting","messagePattern":"unimplemented: dynamic code splitting","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"bindings/binding_core_node/src/bundle.rs","lineNumber":114,"sourceCode":"                                    .cloned(),\n                            )\n                            .collect(),\n                        ..Default::default()\n                    },\n                    Box::new(Hook),\n                );\n\n                let result = bundler\n                    .bundle(self.config.static_items.config.entry.clone().into())\n                    .convert_err()?;\n\n                let result = result\n                    .into_iter()\n                    .map(|bundle| match bundle.kind {\n                        BundleKind::Named { name } | BundleKind::Lib { name } => {\n                            Ok((name, bundle.module))\n                        }\n                        BundleKind::Dynamic => bail!(\"unimplemented: dynamic code splitting\"),\n                    })\n                    .map(|res| {\n                        res.and_then(|(k, m)| {\n                            // TODO: Source map\n                            let minify = self\n                                .config\n                                .static_items\n                                .config\n                                .options\n                                .as_ref()\n                                .map(|v| v.config.minify.into_bool())\n                                .unwrap_or(false);\n\n                            let output = self.swc.print(\n                                &m,\n                                PrintArgs {\n                                    inline_sources_content: true,\n                                    source_map: SourceMapsConfig::Bool(true),","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/bindings/binding_core_node/src/bundle.rs#L96-L132","documentation":"The Node bundle API maps every chunk the SWC bundler produces onto a named output, but when the entry graph yields a dynamic chunk (BundleKind::Dynamic, created by dynamic import() or similar splitting), the binding has no code path for it and bails. This is a hard, explicit feature gap in the binding ('unimplemented'), not a configuration problem. The Rust bundler itself produced the chunk fine; only the Node-side mapping refuses it.","triggerScenarios":"Calling the bundle binding with an entry whose module graph contains import('./lazy.js') (or another dynamic entry form), so bundler.bundle(entry) emits at least one BundleKind::Dynamic chunk alongside the named/lib ones.","commonSituations":"Migrating an app with lazy-loaded routes to SWC bundling; pointing the experimental bundle API at a playground or fixture that uses dynamic imports; adding a single import() during prototyping and suddenly every bundle call fails.","solutions":["Replace dynamic import() with static imports for the graph you hand to this API, or split the app into multiple static entries","Use a bundler with code-splitting support (webpack, rollup, esbuild, or spack driven via swc_core directly) for graphs that need dynamic chunks","Track the SWC repo for dynamic-splitting support in the Node bundle binding before re-enabling import()"],"exampleFix":"// before - entry graph contains dynamic import, binding bails with\n// 'unimplemented: dynamic code splitting'\nimport('./lazy-module.js').then(m => m.run());\n\n// after - static import so the bundler emits only named chunks\nimport * as lazy from './lazy-module.js';\nlazy.run();","handlingStrategy":"try-catch","validationCode":"// reject graphs with dynamic imports before calling the bundle binding\nconst hasDynamicImport = (src) => /\\bimport\\s*\\(/.test(src);\nconst sources = collectEntrySources(entry);\nif (sources.some(hasDynamicImport)) {\n  throw new Error('entry graph uses dynamic import(); Node bundle API cannot split chunks');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const out = bundle(config);\n} catch (e) {\n  if (String(e?.message).includes('dynamic code splitting')) {\n    // fall back to per-entry static bundles or another bundler\n    return bundleEachEntryStatically(config);\n  }\n  throw e;\n}","preventionTips":["Keep the entry graph handed to this API free of import() expressions","Gate the bundle call behind a source scan for dynamic imports in CI","Watch the SWC changelog for dynamic chunk support before adopting lazy loading"],"tags":["swc","bundler","dynamic-import","code-splitting","node-bindings"],"backgroundTag":"unsupported-feature-unimplemented","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}