You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行node --inspect-brk调试Jest时遇ReferenceError错误求助

Fixing "ReferenceError: Unknown option: .debug" in Jest Debug Script for Create React App

Hey there, let's break down why you're hitting this error and how to fix it quickly.

The Root Cause

Your project uses react-scripts (clear from your package.json dependencies and scripts), which wraps Jest and Babel with pre-configured settings to simplify Create React App projects. When you directly call ./node_modules/jest/bin/jest.js in your test:debug script, you're bypassing react-scripts's managed configuration—this leads to Babel not recognizing the settings it expects, hence the "Unknown option: .debug" error.

The Fix

Replace your custom test:debug script with one that uses react-scripts's built-in test runner, which handles all the Babel/Jest setup for you. Update the script in your package.json to:

"test:debug": "node --inspect-brk node_modules/react-scripts/scripts/test.js --runInBand --watch"

Or use this shorter, equivalent version:

"test:debug": "react-scripts --inspect-brk test --runInBand --watch"

Why This Works

react-scripts/scripts/test.js is the entry point Create React App uses for its default test command. It loads all the correct Babel presets, Jest configurations, and environment settings tailored to your React project. By using this instead of calling Jest directly, you avoid the configuration mismatches that triggered the Babel error.

Extra Tips

  • After updating the script, run yarn test:debug and open Chrome to chrome://inspect—you'll see the Node.js debugger session listed, ready to connect for breakpoint debugging.
  • Your Node v10.17.0 and React v16.12.0 versions are fully compatible with react-scripts 3.3.0, so no version conflicts are at play here.
  • Reinstalling node_modules was a good first step, but the issue never lay with dependencies—it was with how you were invoking Jest.

内容的提问来源于stack exchange,提问作者Remi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 13:42:31