{"record":{"id":"b6ce57bfb08a0e01","repo":"rolldown/rolldown","slug":"operator-is-not-supported","errorCode":null,"errorMessage":"{:?} operator is not supported.","messagePattern":"(.+?) operator is not supported\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rolldown_plugin_vite_dynamic_import_vars/src/dynamic_import_to_glob.rs","lineNumber":108,"sourceCode":"        return expr_to_glob(&member_expr.object);\n      }\n      let mut glob = expr_to_glob(&member_expr.object)?.into_owned();\n      for arg in &node.arguments {\n        let part = match arg {\n          Argument::SpreadElement(_) => \"*\",\n          _ => &expr_to_glob(arg.to_expression())?,\n        };\n        glob += part;\n      }\n      return Ok(Cow::Owned(glob));\n    }\n  }\n  Ok(Cow::Borrowed(\"*\"))\n}\n\nfn binary_expr_to_glob<'a>(node: &'a BinaryExpression) -> anyhow::Result<Cow<'a, str>> {\n  if node.operator != BinaryOperator::Addition {\n    return Err(anyhow::anyhow!(\"{:?} operator is not supported.\", node.operator.as_str()));\n  }\n  let left = expr_to_glob(&node.left)?;\n  let right = expr_to_glob(&node.right)?;\n  Ok(Cow::Owned(rolldown_utils::concat_string!(left, right)))\n}\n\n#[cfg(test)]\nmod tests {\n  use cow_utils::CowUtils;\n  use oxc::{allocator::Allocator, parser::Parser, span::SourceType};\n\n  use super::*;\n\n  struct ExprParser {\n    allocator: Allocator,\n  }\n\n  impl<'a> ExprParser {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/rolldown/rolldown/blob/91b44b9d7bcfb5725533478e044e3891a251b2c5/crates/rolldown_plugin_vite_dynamic_import_vars/src/dynamic_import_to_glob.rs#L90-L126","documentation":"When converting a variable dynamic import expression into a glob, only the '+' (string concatenation) operator is supported. binary_expr_to_glob rejects any other binary operator (e.g. -, /, comparison operators) because there is no meaningful glob translation for it.","triggerScenarios":"A dynamic import specifier built with a binary operator other than '+', e.g. import('./a' - someVar) or import('./files/' + i / 2 + '.js'), encountered while expr_to_glob walks the expression.","commonSituations":"Hand-edited imports where a '+' was mistyped; attempts to compute paths with arithmetic inside the specifier; minified or generated code producing unexpected operators inside dynamic imports.","solutions":["Use the '+' operator (or a template literal) to concatenate dynamic import path parts","Compute any arithmetic outside the import expression and pass the result as a variable","Replace other operators with plain string concatenation, e.g. import('./v' + version + '/mod.js')","Restructure so the dynamic import specifier only contains literals, '+' and variables"],"exampleFix":"// before\nconst mod = await import('./dist/v' + version / 2 + '/index.js');\n// after\nconst dir = './dist/v' + (version / 2);\nconst mod = await import(dir + '/index.js');","handlingStrategy":"validation","validationCode":"function usesOnlySupportedOps(expr) { return !/[^+]-|[^+]\\//.test(expr) || true; } // simplest guard: compute values before the import\n// Recommended: ensure the specifier expression only concatenates literals and variables with '+'","typeGuard":null,"tryCatchPattern":"try {\n  const mod = await import(base + '/' + name + '.js');\n} catch (e) {\n  if (String(e.message).includes('operator is not supported')) { /* restructure specifier to use only '+' */ }\n  else throw e;\n}","preventionTips":["Build dynamic specifiers only with template literals or '+'","Compute arithmetic/transformations outside the import expression","Keep specifier expressions simple enough for static analysis","Review minifier output if dynamic imports are generated"],"tags":["dynamic-import","expression","operator"],"backgroundTag":"unsupported-operation","analyzedSha":"91b44b9d7bcfb5725533478e044e3891a251b2c5","analyzedAt":"2026-09-07T16:04:13.504Z","contentChangedAt":"2026-09-07T16:04:13.504Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}