React 16.2项目安装prop-types后出现Cannot find module 'react-dev-utils/clearConsole'错误求助
Hey there, let's work through this error step by step! This issue typically crops up due to dependency mismatches or corrupted installation files after adding prop-types to your React 16.2 project. Here are actionable solutions to get your app running again:
1. Install or Reinstall react-dev-utils
The react-dev-utils package is a critical development dependency (usually bundled with react-scripts), and it might have been missing or corrupted during your prop-types install. Run this command to add it explicitly:
npm install react-dev-utils --save-dev
2. Clean Cache and Reinstall All Dependencies
Sometimes cached files or broken dependency trees cause this error. Follow these steps to do a fresh install:
- Delete the
node_modulesfolder andpackage-lock.jsonfile:# For macOS/Linux rm -rf node_modules package-lock.json # For Windows (Command Prompt) rmdir /s /q node_modules del package-lock.json - Clear your npm cache to remove any corrupted cached packages:
npm cache clean --force - Reinstall all dependencies from scratch:
npm install
3. Ensure Compatibility with react-scripts
React 16.2 works best with specific versions of react-scripts (the v2.x series, since newer versions drop support for older React releases). If your react-scripts version is too new or outdated, install a compatible version:
npm install react-scripts@2.1.8 --save-dev
This version is known to play nicely with React 16.2 and includes the correct react-dev-utils dependency.
4. Verify Dependency Versions
Double-check your package.json to confirm:
reactis set to^16.2.0react-scriptsmatches the compatible version you installedreact-dev-utilsis listed underdevDependencies
If you still run into issues, try deleting the package-lock.json again and repeating the reinstall step—sometimes lock files can hold onto outdated or conflicting dependency references.
内容的提问来源于stack exchange,提问作者azmul hossain

