Automated scanner for Node.js projects — finds bugs across backend, frontend, and config.
node scripts/auto-debug.js <project-dir>
Options:
--build — Also run npm run build and capture compilation errors.push() on undeclared variablesDate.now(), Math.random() in render (should be in useEffect or useState)window/document access outside useEffectisLoading/isFetchingReport saved to with issues grouped by severity:
Exit code: 1 if any critical issues found, 0 otherwise.
Date.now()/new Date() in render:
// ❌ Bad — causes hydration mismatch
const now = Math.floor(Date.now() / 1000);
// ✅ Good — guard with isMounted
const [isMounted, setIsMounted] = useState(false);
useEffect(() => { setIsMounted(true); }, []);
const now = isMounted ? Math.floor(Date.now() / 1000) : 0;
Math.random() in render:
// ❌ Bad — different on server vs client
<div style={{ left: `${Math.random() * 100}%` }} />
// ✅ Good — pre-generate in useState (runs once)
const [particles] = useState(() =>
Array.from({ length: 10 }, () => ({
left: `${Math.random() * 100}%`,
}))
);
window/document access:
// ❌ Bad — crashes during SSR
const width = window.innerWidth;
// ✅ Good — only after mount
const [width, setWidth] = useState(0);
useEffect(() => setWidth(window.innerWidth), []);
共 1 个版本