dianping/cat · error · SyntaxError
@namespace not allowed here.
Error message
@namespace not allowed here.
What it means
Thrown when `@namespace` appears after rules that must follow it: `@namespace` declarations must come after `@charset`/`@import` but before any style rules (and before any element-type selectors that would rely on the namespace). The parser consumes the `@namespace` via `_namespace(false)` and throws `SyntaxError('@namespace not allowed here.')` at its token position; in non-strict mode it degrades to an 'error' event.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-css.js:2069
break;
case Tokens.S:
this._readWhitespace();
break;
default:
if(!this._ruleset()){
switch(tt){
case Tokens.CHARSET_SYM:
token = tokenStream.LT(1);
this._charset(false);
throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
case Tokens.IMPORT_SYM:
token = tokenStream.LT(1);
this._import(false);
throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
case Tokens.NAMESPACE_SYM:
token = tokenStream.LT(1);
this._namespace(false);
throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
default:
tokenStream.get(); //get the last token
this._unexpectedToken(tokenStream.token());
}
}
}
} catch(ex) {
if (ex instanceof SyntaxError && !this.options.strict){
this.fire({
type: "error",
error: ex,
message: ex.message,
line: ex.line,
col: ex.col
});
} else {
throw ex;View on GitHub (pinned to e815e74d4c)
Solutions
- Move `@namespace` statements directly after `@charset`/`@import` and before all style rules.
- If you do not actually need XML namespaces (plain HTML CSS), delete the `@namespace` line.
- If required, restructure so namespaced selectors live in their own file parsed/imported in correct order.
- Lint for at-rule ordering (@charset → @import → @namespace → rules) in CI.
Example fix
/* before */
svg|rect { fill: red; }
@namespace svg url(http://www.w3.org/2000/svg); /* not allowed here */
/* after */
@namespace svg url(http://www.w3.org/2000/svg);
svg|rect { fill: red; } Defensive patterns
Strategy: validation
Validate before calling
function namespaceBeforeRules(css) {
var m = css.match(/@namespace[^;]+;/);
if (!m) return true;
var rulesBefore = css.slice(0, m.index).replace(/@charset[^;]*;|@import[^;]+;/g, '').trim();
return rulesBefore === '';
} Try / catch
try {
parser.parse(css);
} catch (ex) {
if (/@namespace not allowed/.test(ex.message)) { moveToTop('@namespace'); return; }
throw ex;
} Prevention
- Keep the header order @charset → @import → @namespace → rules in every file and in concatenated output.
- Delete @namespace from HTML-only stylesheets where it serves no purpose.
- Add an at-rule-order lint rule so merges cannot silently break ordering.
When it happens
Trigger: `@namespace svg url(...);` placed after a ruleset, `@media`, or `@font-face`; XML-targeted stylesheets where a rule was added above the namespace; generated SVG CSS that appends namespaces at the end.
Common situations: Editing SVG-styled CSS and appending the namespace late; merge conflicts resolved by putting the namespace block below rules; tooling that injects a prefix block before a hand-written namespace.
Related errors
- Unknown @ rule.
- @charset not allowed here.
- @import not allowed here.
- Expected "{pattern}" at line {line}, col {col}.
- Expected {name} at line {line}, col {col}.
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/2d4a1a9c469045e4.
Report an issue: GitHub.