Comprehensive troubleshooting guide for common issues, debugging strategies, and performance problems in Legal Markdown JS. This guide helps users and developers quickly identify and resolve problems.
- Quick Diagnostics
- Common Issues
- Error Messages Guide
- Debug Mode and Tools
- Performance Issues
- Installation Problems
- Configuration Issues
- Processing Errors
- Output Problems
- Advanced Debugging
- Getting Help
When encountering issues, run through this quick checklist:
# 1. Check Legal Markdown version
legal-md --version
# 2. Verify Node.js version (requires 18+)
node --version
# 3. Run built-in diagnostics
legal-md --validate document.md
# 4. Test with minimal example
echo "# Test" | legal-md --stdin --stdout
# 5. Check for recent changes
git log --oneline -5# Run comprehensive health check
legal-md --health-check
# Verify installation integrity
npm ls legal-markdown-js
# Check for conflicting dependencies
npm ls | grep -E "(legal|markdown)"
# Test file permissions
legal-md --test-permissions ./# Check environment variables
env | grep -i legal
# Verify file system access
ls -la ./templates 2>/dev/null || echo "Templates directory not found"
# Test memory and disk space
df -h .
free -h 2>/dev/null || vm_statProblem: Error: File not found: ./template.md
Causes and Solutions:
# Check file exists and has correct permissions
ls -la ./template.md
# Verify current working directory
pwd
ls -la
# Use absolute path
legal-md /full/path/to/template.md output.pdf
# Check file permissions
chmod +r ./template.mdDebug with:
# Enable verbose output
legal-md --verbose template.md
# Test file access
legal-md --test-file-access template.mdProblem: YamlParsingError: Invalid YAML syntax
Common YAML Issues:
# ❌ Bad: Mixed tabs and spaces
---
title: "Contract"
amount: 50000 # Tab used here
---
# ✅ Good: Consistent spacing
---
title: "Contract"
amount: 50000
---
# ❌ Bad: Unquoted special characters
---
title: Contract: Terms & Conditions
email: user@domain.com
---
# ✅ Good: Quoted special characters
---
title: "Contract: Terms & Conditions"
email: "user@domain.com"
---
# ❌ Bad: Improper list formatting
---
services:
- Consulting
- Analysis # Wrong indentation
---
# ✅ Good: Proper list formatting
---
services:
- Consulting
- Analysis
---Debug YAML:
# Validate YAML syntax only
legal-md --validate-yaml document.md
# Extract and test YAML
legal-md --extract-yaml document.md > test.yaml
legal-md --test-yaml test.yaml
# Use YAML linter
npm install -g yaml-lint
yaml-lint document.mdProblem: Template fields not processing or showing as {{field_name}}
Debugging Steps:
# 1. Check field definitions
legal-md --list-fields document.md
# 2. Validate field names
legal-md --validate-fields document.md
# 3. Test with simple template
echo '---
name: "Test"
---
Hello {{name}}!' | legal-md --stdin --stdout
# 4. Debug field resolution
legal-md --debug-fields document.mdCommon Field Problems:
<!-- ❌ Bad: Undefined field -->
Client: {{client_nam}} <!-- Typo: should be client_name -->
<!-- ❌ Bad: Invalid characters -->
Amount: {{contract-value}} <!-- Use underscore: contract_value -->
<!-- ❌ Bad: Nested braces -->
Result: {{{{calculation}}}} <!-- Should be: {{calculation}} -->
<!-- ✅ Good: Proper field reference -->
Client: {{client_name}} Amount: {{contract_value}} Result: {{calculation}}Problem: ImportError: Cannot resolve import './sections/terms.md'
Debugging Imports:
# 1. Verify import path
ls -la ./sections/terms.md
# 2. Check relative path resolution
legal-md --debug-imports document.md
# 3. Test import individually
legal-md ./sections/terms.md
# 4. Validate import syntax
grep "@@include" document.mdImport Best Practices:
<!-- ✅ Good: Relative paths -->
@@include ./sections/definitions.md @@include ../common/signatures.md
<!-- ❌ Bad: Absolute paths (security risk) -->
@@include /etc/passwd @@include C:\Windows\System32\config
<!-- ✅ Good: Consistent path format -->
@@include ./terms.md @@include ./conditions.md
<!-- ❌ Bad: Mixed path separators -->
@@include ./terms.md @@include .\conditions.mdProblem: Generated PDF/HTML is empty or malformed
Debugging Output:
# 1. Test with markdown output first
legal-md document.md output.md
# 2. Verify content processing
legal-md --debug --no-output document.md
# 3. Test output formats individually
legal-md --html document.md test.html
legal-md --pdf document.md test.pdf
# 4. Check output directory permissions
ls -la output/
mkdir -p output && chmod 755 outputYamlParsingError: bad indentation of a mapping entry at line 5, column 3
Solution:
- Check line 5 in YAML frontmatter
- Ensure consistent indentation (spaces only)
- Verify proper YAML structure
# Extract and validate YAML
sed -n '/^---$/,/^---$/p' document.md | legal-md --validate-yaml --stdinTemplateError: Template processing failed for field 'client_name': field not found
Solution:
- Add field to YAML frontmatter
- Check for typos in field name
- Verify field name uses valid characters
---
# Add missing field
client_name: 'Acme Corporation'
---CircularReferenceError: Circular reference detected: document.md -> terms.md -> document.md
Solution:
- Review import chain
- Remove circular imports
- Restructure document hierarchy
# Visualize import dependencies
legal-md --show-dependencies document.mdSecurityError: Path traversal detected in import: ../../../etc/passwd
Solution:
- Use relative paths within project
- Avoid directory traversal (
../) - Configure allowed paths
# Configure allowed paths
legal-md --allowed-paths ./templates:./sections document.mdWriteError: Permission denied writing to /protected/output.pdf
Solution:
- Check output directory permissions
- Verify disk space
- Use writable output path
# Fix permissions
chmod 755 output/
# Check disk space
df -h .# Basic debug mode
legal-md --debug document.md
# Verbose debug output
legal-md --debug --verbose document.md
# Debug specific components
legal-md --debug-yaml --debug-imports --debug-fields document.md
# Debug with performance profiling
legal-md --debug --profile document.md# Save debug output for analysis
legal-md --debug document.md 2> debug.log
# Filter debug information
grep -E "(ERROR|WARN|DEBUG)" debug.log
# Extract timing information
grep "Duration:" debug.log | sort -k2 -n# Comprehensive system diagnostics
legal-md --diagnostics
# Test specific functionality
legal-md --test-yaml-parser
legal-md --test-import-resolver
legal-md --test-template-engine
# Benchmark performance
legal-md --benchmark document.md# debug-config.yml
debug:
enabled: true
level: 'verbose'
components:
- yaml-parser
- template-engine
- import-resolver
output:
file: './debug.log'
console: true
performance:
enabled: true
threshold: 100 # milliseconds# Use custom debug configuration
legal-md --debug-config debug-config.yml document.mdSymptoms:
- Processing takes longer than 30 seconds
- High CPU usage
- System becomes unresponsive
Diagnosis:
# 1. Profile processing time
time legal-md document.md output.pdf
# 2. Monitor resource usage
# On Linux/macOS:
top -p $(pgrep legal-md)
# On macOS:
ps aux | grep legal-md
# 3. Analyze document complexity
legal-md --analyze-complexity document.md
# 4. Test with simplified version
legal-md --no-imports --no-mixins document.md output.pdfSolutions:
# Enable performance optimizations
legal-md --optimize-performance document.md
# Use streaming processing for large files
legal-md --stream-processing large-document.md
# Disable field tracking for production
legal-md --no-field-tracking document.md final.pdf
# Process in batch mode
legal-md --batch *.md --output-dir ./processed/Symptoms:
- Out of memory errors
- System swap usage increases
- Processing fails on large documents
Diagnosis:
# Monitor memory usage
legal-md --memory-monitor document.md
# Check document size
ls -lh document.md
wc -l document.md
# Test with memory limits
legal-md --max-memory 512MB document.mdSolutions:
# Use chunked processing
legal-md --chunk-size 1MB large-document.md
# Enable garbage collection
legal-md --gc-aggressive document.md
# Process in separate process
timeout 300 legal-md document.md || echo "Processing timeout"Symptoms:
- Slow file operations
- Import delays
- Network timeout on remote imports
Diagnosis:
# Check disk performance
iostat -x 1 5 # Linux
# or
iotop # If available
# Test file access speed
time ls -la ./templates/
# Monitor import resolution
legal-md --debug-imports --time-imports document.mdSolutions:
# Use local imports only
legal-md --local-imports-only document.md
# Cache imports
legal-md --cache-imports --cache-dir ./cache document.md
# Parallel import processing
legal-md --parallel-imports document.mdProblem: Error: Node.js version 16.x is not supported
Solution:
# Check current Node.js version
node --version
# Install/update Node.js (using nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 18
nvm use 18
# Or using package manager
# Ubuntu/Debian:
sudo apt update && sudo apt install nodejs npm
# macOS:
brew install node@18Problem: npm ERR! peer dep missing: remark@^14.0.0
Solution:
# Clear npm cache
npm cache clean --force
# Reinstall with peer dependencies
npm install --legacy-peer-deps
# Or install specific versions
npm install remark@^14.0.0 legal-markdown-js
# Use yarn as alternative
yarn installProblem: Command not found after installation
Solution:
# Check global installation
npm list -g legal-markdown-js
# Install globally if needed
npm install -g legal-markdown-js
# Or use npx for local installation
npx legal-markdown-js document.md
# Check PATH
echo $PATH | grep npmProblem: EACCES: permission denied
Solution:
# Fix npm permissions
npm config set prefix ~/.npm-global
export PATH=~/.npm-global/bin:$PATH
# Or use sudo (not recommended)
sudo npm install -g legal-markdown-js
# Better: use nvm for user-level installation
nvm use 18
npm install -g legal-markdown-jsProblem: Configuration not loading or invalid
Diagnosis:
# Check config file location
legal-md --config-path
# Validate configuration
legal-md --validate-config
# Use default config
legal-md --default-config document.md
# Debug config loading
legal-md --debug-config document.mdCommon Config Issues:
// ❌ Bad: Invalid JSON
{
"enableFieldTracking": true, // Trailing comma
}
// ✅ Good: Valid JSON
{
"enableFieldTracking": true
}
// ❌ Bad: Wrong data types
{
"maxFileSize": "10MB", // Should be number
"enableDebug": "true" // Should be boolean
}
// ✅ Good: Correct data types
{
"maxFileSize": 10485760,
"enableDebug": true
}Problem: Environment configuration not working
Check Environment:
# List Legal Markdown environment variables
env | grep -i legal
# Check specific variables
echo $LEGAL_MD_CONFIG_PATH
echo $LEGAL_MD_DEBUG
echo $LEGAL_MD_TEMPLATE_PATH
# Set environment variables
export LEGAL_MD_DEBUG=true
export LEGAL_MD_CONFIG_PATH=./config.jsonProblem: Helper functions not working
Diagnosis:
# List available helpers
legal-md --list-helpers
# Test helper individually
echo '{{formatDate("2025-08-01", "DD/MM/YYYY")}}' | legal-md --test-helper --stdin
# Debug helper execution
legal-md --debug-helpers document.mdHelper Issues:
<!-- ❌ Bad: Wrong syntax -->
{{formatDate(contract_date, DD/MM/YYYY)}} <!-- Missing quotes -->
<!-- ❌ Bad: Unknown helper -->
{{calculateTax(amount, rate)}} <!-- Helper doesn't exist -->
<!-- ✅ Good: Correct syntax -->
{{formatDate(contract_date, "DD/MM/YYYY")}}
<!-- ✅ Good: Available helper -->
{{formatCurrency(amount, "EUR")}}Problem: Cannot resolve imports despite files existing
Debug Steps:
# Check import resolution
legal-md --trace-imports document.md
# Test import path resolution
legal-md --resolve-path "./sections/terms.md" --base-path "."
# Verify file encoding
file document.md sections/terms.md
# Check for hidden characters
cat -A document.md | grep "@@include"Problem: Fields showing as {{field_name}} in output
Debug Process:
# 1. List all fields in document
legal-md --extract-fields document.md
# 2. Show field values
legal-md --show-field-values document.md
# 3. Test field resolution
legal-md --test-fields document.md
# 4. Debug YAML parsing
legal-md --debug-yaml document.mdProblem: PDF output is blank or corrupted
Solutions:
# Test HTML generation first
legal-md --html document.md test.html
# Use alternative PDF engine
legal-md --pdf-engine puppeteer document.md output.pdf
# Check for PDF dependencies
legal-md --check-pdf-deps
# Generate with debug info
legal-md --pdf --debug-pdf document.md debug.pdfProblem: HTML output has broken formatting
Debug Steps:
# Validate HTML structure
legal-md --html --validate-html document.md
# Test CSS loading
legal-md --html --inline-css document.md
# Check for encoding issues
legal-md --html --encoding utf-8 document.md
# Debug field highlighting
legal-md --html --debug-highlighting document.mdProblem: Special characters not displaying correctly
Solutions:
# Specify input encoding
legal-md --input-encoding utf-8 document.md
# Force output encoding
legal-md --output-encoding utf-8 document.md
# Check file encoding
file -i document.md
# Convert encoding if needed
iconv -f windows-1252 -t utf-8 document.md > document-utf8.mdFor remote imports or API integrations:
# Enable network debugging
export DEBUG=legal-md:network
legal-md document.md
# Test network connectivity
curl -I https://templates.example.com/terms.md
# Use proxy if needed
export HTTP_PROXY=http://proxy.company.com:8080
legal-md document.mdFor memory leak investigation:
# Generate heap snapshot
legal-md --heap-snapshot document.md
# Profile memory usage
legal-md --memory-profile document.md
# Monitor memory over time
while true; do
ps -o pid,vsz,rss,comm -p $(pgrep legal-md)
sleep 1
doneFor detailed performance analysis:
# Generate performance profile
legal-md --performance-profile document.md
# Use Node.js profiler
node --prof `which legal-md` document.md
node --prof-process isolate-*.log > profile.txt
# Benchmark against baseline
legal-md --benchmark --baseline ./benchmarks/ document.mdAnalyzing debug logs for patterns:
# Extract error patterns
grep -E "(ERROR|FATAL)" debug.log | sort | uniq -c
# Timing analysis
grep "Duration:" debug.log | awk '{sum+=$2; count++} END {print "Average:", sum/count "ms"}'
# Memory usage patterns
grep "Memory:" debug.log | tail -20
# Find performance bottlenecks
grep "Duration:" debug.log | sort -k2 -nr | head -10-
Documentation: Check relevant sections
-
Built-in Help:
legal-md --help legal-md --help-examples legal-md --troubleshoot
-
Online Resources:
- GitHub Issues: Search existing issues
- Documentation: Check latest updates
- Community Forums: Ask questions
When reporting issues, include:
# System information
legal-md --version
node --version
npm --version
uname -a # or system info
# Configuration
legal-md --show-config
# Error reproduction
legal-md --debug document.md 2>&1 | tee error.log
# File information
ls -la document.md
file document.md
head -20 document.md## Problem Description
Brief description of the issue.
## Environment
- Legal Markdown JS version:
- Node.js version:
- Operating System:
- Installation method:
## Steps to Reproduce
1. Create file with content...
2. Run command...
3. Observe error...
## Expected Behavior
What should happen.
## Actual Behavior
What actually happens.
## Debug InformationAttach debug.log file
## Error Logs
Paste relevant error messages
## Additional Context
Any other relevant information.
When everything fails:
# 1. Complete reset
rm -rf node_modules package-lock.json
npm cache clean --force
npm install
# 2. Use minimal configuration
legal-md --no-config --default-options document.md
# 3. Test with minimal document
echo -e "---\ntitle: Test\n---\n# {{title}}" | legal-md --stdin --stdout
# 4. Reinstall from scratch
npm uninstall -g legal-markdown-js
npm install -g legal-markdown-js@latest
# 5. Check for system issues
npm doctor
node -e "console.log('Node.js working')"- GitHub Discussions: For questions and community support
- Stack Overflow: Tag questions with
legal-markdown-js - Discord/Slack: Real-time community chat (if available)
- Documentation Issues: Report doc problems on GitHub
Remember to search existing issues before creating new ones, and provide complete diagnostic information to help maintainers assist you quickly.
- Error Handling - Comprehensive error handling strategies
- Performance Guide - Performance optimization and troubleshooting
- Configuration - Configuration options and examples
- Security - Security-related troubleshooting
- Development Guide - Development environment setup