{"record":{"id":"47cfb95bd31fc5c4","repo":"rolldown/rolldown","slug":"moduletype-token-should-be-followed-by-a-string-b","errorCode":null,"errorMessage":"ModuleType token should be followed by a string, but got {other:?}","messagePattern":"ModuleType token should be followed by a string, but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rolldown_utils/src/filter_expression.rs","lineNumber":301,"sourceCode":"        let key = match pop(tokens)? {\n          Token::String(key) => key,\n          other => anyhow::bail!(\"key of `Query` should be a string, but got {other:?}\"),\n        };\n        let value = match pop(tokens)? {\n          Token::String(v) => QueryValue::String(v),\n          Token::Regex(v) => QueryValue::Regex(v),\n          Token::Boolean(v) => QueryValue::Boolean(v),\n          other => anyhow::bail!(\n            \"value of `Query` should be a string, regex, or boolean, but got {other:?}\"\n          ),\n        };\n        Ok(FilterExpr::Query(key, value))\n      }\n      Token::ModuleType => {\n        let string = match pop(tokens)? {\n          Token::String(s) => s,\n          other => {\n            anyhow::bail!(\"ModuleType token should be followed by a string, but got {other:?}\")\n          }\n        };\n        Ok(FilterExpr::ModuleType(string))\n      }\n      Token::And(arg_count) => {\n        let mut args = Vec::with_capacity(arg_count as usize);\n        for _ in 0..arg_count {\n          args.push(rec(tokens)?);\n        }\n        Ok(FilterExpr::And(args))\n      }\n      Token::Or(arg_count) => {\n        let mut args = Vec::with_capacity(arg_count as usize);\n        for _ in 0..arg_count {\n          args.push(rec(tokens)?);\n        }\n        Ok(FilterExpr::Or(args))\n      }","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/rolldown/rolldown/blob/91b44b9d7bcfb5725533478e044e3891a251b2c5/crates/rolldown_utils/src/filter_expression.rs#L283-L319","documentation":"The `moduleType` operator in a filter expression must be followed immediately by a string literal naming the module type. The parser (`rec`, invoked from public `parse`) bails with this error when any other token follows the `moduleType` token, because `FilterExpr::ModuleType` only carries a string.","triggerScenarios":"Parsing an expression like `moduleType(/regex/)` or `moduleType(true)`, or an expression that ends right after `moduleType` so a leftover/truncated token is popped instead of a string.","commonSituations":"Typos in hand-written serialized filter expressions used by builtin plugin filters; passing a regex instead of a string for the module type; string truncation when the expression is embedded in JSON config and quotes are mis-escaped.","solutions":["Quote the module type value, e.g. `moduleType('js')`.","Verify the expression is complete and not truncated after the `moduleType` token.","Use only string module type values matching known module types (js, jsx, ts, css, json, asset, ...)."],"exampleFix":"// before\nparse(\"moduleType(/css/)\")\n// after\nparse(\"moduleType('css')\")","handlingStrategy":"validation","validationCode":"// before serializing moduleType filter\nfunction assertModuleType(v) {\n  if (typeof v !== 'string') {\n    throw new TypeError(`moduleType expects a string, got: ${typeof v}`);\n  }\n}","typeGuard":"function isStringModuleType(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  parse(expr);\n} catch (e) {\n  if (String(e).includes('ModuleType token should be followed by a string')) {\n    // correct the expression: moduleType('...')\n  }\n  throw e;\n}","preventionTips":["Quote the module type: moduleType('css'), never moduleType(/css/).","Check the expression is not truncated right after moduleType.","Reuse shared constants for module type names to avoid typos."],"tags":["filter-expression","parser","module-type","invalid-value"],"backgroundTag":"invalid-argument-value","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"}