unclecode/crawl4ai · error · ValueError
C4A Script compilation error (script {i+1}): Line {error.l
Error message
C4A Script compilation error (script {i+1}):
Line {error.line}, Column {error.column}: {error.message}
Code: {error.source_line}
Suggestion: {error.suggestions[0].message} What it means
Raised when a js_source entry written in C4A script syntax (crawl4ai's JS DSL) fails to compile. The message includes script index, error line/column, the offending source line, and the first compiler suggestion. This happens during CrawlerRunConfig construction, before any browser launches.
Source
Thrown at crawl4ai/async_configs.py:1981
# Compile each script
compiled_js = []
for i, script in enumerate(scripts):
result = compile(script)
if result.success:
compiled_js.extend(result.js_code)
else:
# Format error message following existing patterns
error = result.first_error
error_msg = (
f"C4A Script compilation error (script {i+1}):\n"
f" Line {error.line}, Column {error.column}: {error.message}\n"
f" Code: {error.source_line}"
)
if error.suggestions:
error_msg += f"\n Suggestion: {error.suggestions[0].message}"
raise ValueError(error_msg)
self.js_code = compiled_js
except ImportError:
raise ValueError(
"C4A script compiler not available. "
"Please ensure crawl4ai.script module is properly installed."
)
except Exception as e:
# Re-raise with context
if "compilation error" not in str(e).lower():
raise ValueError(f"Failed to compile C4A script: {str(e)}")
raise
def is_match(self, url: str) -> bool:
"""Check if this config matches the given URL.
Args:View on GitHub (pinned to 7e80152142)
Solutions
- Read the reported Line/Column and Code — they pinpoint the exact offending token in your js_source entry
- Apply the included Suggestion from the compiler
- Verify you are using valid C4A syntax; if you meant plain JavaScript, ensure the string is not being routed through the C4A compiler (check js_source vs js_code usage)
- Reproduce in isolation: compile just that script with crawl4ai.script's compiler to iterate faster
Example fix
// before js_source='''wait for "#result" then click it twice and extract title''' // after (fix per reported line/column + suggestion) js_source='''wait for selector "#result" click "#result" twice''' // then extract via extraction_strategy
Defensive patterns
Strategy: try-catch
Validate before calling
from crawl4ai.script import compile_c4a_script # name per your version
for i, src in enumerate(js_source_list or []):
result = compile_c4a_script(src) # dry-run before building the config
if not result.success:
raise SystemExit(f"script {i}: {result.first_error.message}") Try / catch
try:
cfg = CrawlerRunConfig(js_source=scripts)
except ValueError as e:
if "compilation error" in str(e).lower():
log_script_error(e); exit(2) # authoring bug: fix the script
raise Prevention
- Dry-run compile C4A scripts in CI before deploy
- Keep scripts in files and lint them in a pre-commit hook
- Fix the reported line/column first; suggestions usually resolve cascades
When it happens
Trigger: Including a js_source string with C4A DSL syntax that has a syntax error — wrong keyword, unbalanced brace, invalid selector expression; multiple scripts report their 1-based index.
Common situations: Hand-writing C4A scripts for the first time; editing a working script and introducing a typo; mixing plain JavaScript and C4A DSL syntax in one string.
Related errors
- Failed to compile C4A script: {str(e)}
- Circular include {p}
- Unknown procedure {c.args[0]!r}
- Container not found: ${config.container_selector}
- Timeout after {timeout}ms waiting for selector '{wait_for}'
AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14).
Data as JSON: /api/errors/9a9bba625d06ed32.
Report an issue: GitHub.