Troubleshooting
Common issues and solutions when using next-introspect
Troubleshooting
This guide helps you resolve common issues and problems when using next-introspect.
Installation Issues
Command Not Found
Problem: next-introspect: command not found
Solutions:
-
Global Installation Check:
# Install globally npm install -g next-introspect # or bun add -g next-introspect # Check if installed which next-introspect next-introspect --version -
PATH Issues:
- On macOS/Linux, check if npm global bin directory is in PATH
- On Windows, restart terminal or VS Code
- Try using
npx next-introspectinstead
-
Permission Issues:
# Try with sudo (not recommended) sudo npm install -g next-introspect # Or use a version manager bun add -g next-introspect
Module Not Found (Local Installation)
Problem: Cannot find module 'next-introspect'
Solutions:
-
Install Locally:
npm install next-introspect # or bun add next-introspect -
Use npx:
npx next-introspect introspect . -
Check package.json:
{ "devDependencies": { "next-introspect": "^0.3.16" } }
Analysis Errors
Invalid Next.js Project
Problem: Error: Invalid Next.js project: /path/to/project
Solutions:
-
Check Project Structure:
- Ensure
package.jsonexists with Next.js dependency - Check for
app/directory (App Router) orpages/directory (Pages Router) - Verify Next.js is listed in dependencies
- Ensure
-
Correct Package.json:
{ "dependencies": { "next": "^14.0.0" } } -
Framework Detection:
# Check if Next.js is detected ls -la package.json grep -i next package.json
No Routes Found
Problem: Analysis completes but no routes are found
Solutions:
-
Check Directory Structure:
# App Router ls -la app/ ls -la app/**/ # Pages Router ls -la pages/ ls -la pages/**/ -
File Extensions:
- Ensure files have correct extensions:
.js,.jsx,.ts,.tsx - Check for TypeScript configuration if using
.ts/.tsx
- Ensure files have correct extensions:
-
Special Files:
- App Router: Check for
page.tsx,layout.tsx,route.ts - Pages Router: Check for page files and API routes
- App Router: Check for
Permission Errors
Problem: EACCES: permission denied or EPERM: operation not permitted
Solutions:
-
File Permissions:
# Check permissions ls -la /path/to/project # Fix permissions chmod -R 755 /path/to/project -
Run as Administrator:
# On macOS/Linux sudo next-introspect introspect . # On Windows (PowerShell as Admin) next-introspect introspect . -
Node Modules:
# Clear and reinstall rm -rf node_modules package-lock.json npm install
Output Issues
File Not Written
Problem: Analysis runs but output file is not created
Solutions:
-
Directory Permissions:
# Check write permissions touch test-output.json && rm test-output.json # Create directory if needed mkdir -p output/dir/ -
Relative Paths:
# Use absolute paths next-introspect introspect . --output /full/path/to/output.json # Or ensure current directory is writable pwd && ls -la -
File Locks:
- Close any applications that might have the file open
- Wait a moment if another process is writing to the file
Invalid JSON Output
Problem: JSON output is malformed or unreadable
Solutions:
-
Pretty Print:
next-introspect introspect . --format json --indent 2 --output routes.json -
Validate JSON:
# Check if valid JSON cat routes.json | jq . > /dev/null && echo "Valid JSON" || echo "Invalid JSON" -
Large Files:
- Use
--indent 0for compact JSON - Split analysis if project is very large
- Use
TypeScript Compilation Errors
Problem: Generated TypeScript file has compilation errors
Solutions:
-
Type Imports:
// Ensure proper imports in generated file import type { RouteBuilder } from 'next-introspect'; -
Type Conflicts:
- Check for conflicting type definitions
- Use namespace imports to avoid conflicts
-
Strip Prefixes:
# Use strip-prefixes to avoid path issues next-introspect introspect . --format typescript --strip-prefixes "/api/" "/_next/"
Watch Mode Issues
Watch Not Detecting Changes
Problem: Watch mode doesn't react to file changes
Solutions:
-
File Types:
- Watch mode only monitors specific file types
- Ensure changes are to
.js,.jsx,.ts,.tsx, or.jsonfiles
-
Ignored Directories:
- Changes in
node_modules/,.next/,.git/are ignored - Move files outside ignored directories
- Changes in
-
Debounce Timing:
- Wait at least 300ms between changes
- Large projects may need longer debounce
Watch Process Won't Stop
Problem: Ctrl+C doesn't stop watch mode
Solutions:
-
Force Kill:
# Find process ps aux | grep next-introspect # Kill process kill -9 <PID> -
Port Conflicts:
- Check if another process is using the same resources
- Restart terminal
High CPU Usage in Watch Mode
Problem: Watch mode consumes excessive CPU
Solutions:
-
Reduce Analysis Depth:
next-introspect introspect . --watch --mode basic -
Exclude Unnecessary Files:
next-introspect introspect . --watch --exclude-fields "componentTypes,exports" -
Increase Debounce:
- Currently fixed at 300ms
- Consider using file system events instead
Configuration Issues
Metadata File Not Found
Problem: --metadata file.json shows warning about missing file
Solutions:
-
File Path:
# Check file exists ls -la metadata.json # Use absolute path next-introspect introspect . --metadata /full/path/to/metadata.json -
File Format:
{ "/route/path": { "title": "Route Title", "description": "Route description" } } -
TOML Support:
- TOML support is limited
- Use JSON format for best compatibility
Invalid Configuration Options
Problem: Error: Invalid [option] '[value]'
Solutions:
-
Check Valid Values:
--mode:basic,detailed,comprehensive--format:object,json,markdown,typescript--path-style:absolute,relative-to-project,relative-to-app,relative-to-pages,strip-prefix
-
Case Sensitivity:
- All option values are case-sensitive
- Use exact values as shown in help
Path Style Issues
Problem: Path formatting doesn't work as expected
Solutions:
-
App/Pages Directories:
# Ensure correct directories exist ls -la app/ pages/ -
Strip Prefix:
# Verify prefix exists in paths next-introspect introspect . --format json | grep "filePath" -
Show File Paths:
# Add --show-file-paths to see file path formatting next-introspect introspect . --path-style relative-to-project --show-file-paths
Performance Issues
Slow Analysis
Problem: Analysis takes too long
Solutions:
-
Use Basic Mode:
next-introspect introspect . --mode basic -
Exclude Fields:
next-introspect introspect . --exclude-fields "componentTypes,exports,dataFetching" -
Limit Depth:
- Currently analyzes entire project
- Consider analyzing specific directories
Memory Issues
Problem: Out of memory errors
Solutions:
-
Increase Memory:
NODE_OPTIONS="--max-old-space-size=4096" next-introspect introspect . -
Reduce Analysis:
next-introspect introspect . --mode basic --exclude-fields "exports,dataFetching" -
Split Analysis:
- Analyze different parts of the project separately
- Use programmatic API for custom analysis
Large Output Files
Problem: Generated files are too large
Solutions:
-
Field Exclusion:
next-introspect introspect . --exclude-fields "filePath,componentTypes,exports" -
Compact JSON:
next-introspect introspect . --format json --indent 0 -
Split Output:
- Generate separate files for different route types
- Use programmatic API to filter results
Framework-Specific Issues
App Router Issues
Problem: App Router routes not detected correctly
Solutions:
-
File Structure:
app/ ├── layout.tsx ├── page.tsx ├── blog/ │ ├── page.tsx │ └── [slug]/ │ └── page.tsx └── api/ └── users/ └── route.ts -
Special Files:
- Ensure correct file names:
page.tsx,layout.tsx,route.ts - Check for TypeScript configuration
- Ensure correct file names:
-
Route Groups:
# Route groups should be in parentheses ls -la app/(group)/
Pages Router Issues
Problem: Pages Router routes not detected
Solutions:
-
Directory Structure:
pages/ ├── index.tsx ├── about.tsx ├── blog/ │ ├── index.tsx │ └── [slug].tsx └── api/ └── users.ts -
API Routes:
- API routes should export HTTP method handlers
- Check file exports
-
Special Pages:
_app.tsx,_document.tsx,_error.tsxare detected as special pages
Mixed Router Issues
Problem: Both App and Pages routers detected but causing conflicts
Solutions:
-
Choose Primary Router:
# Analysis works with both, but focus on one next-introspect introspect . --format json | jq '.project.router' -
Separate Analysis:
- Analyze App Router routes: filter by
router === "app" - Analyze Pages Router routes: filter by
router === "pages"
- Analyze App Router routes: filter by
Integration Issues
Build Tool Integration
Problem: next-introspect doesn't work in build scripts
Solutions:
-
Script Timing:
{ "scripts": { "build": "next-introspect introspect . && next build" } } -
Error Handling:
{ "scripts": { "build": "next-introspect introspect . || echo 'Route analysis failed' && next build" } } -
Conditional Execution:
{ "scripts": { "build": "if [ \"$CI\" != \"true\" ]; then next-introspect introspect .; fi && next build" } }
CI/CD Issues
Problem: next-introspect fails in CI environment
Solutions:
-
Dependencies:
- name: Install next-introspect run: npm install -g next-introspect -
Permissions:
- name: Analyze routes run: next-introspect introspect . --output routes.json -
Caching:
- name: Cache node modules uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Debug Mode
Verbose Output
# Enable verbose logging (if available)
DEBUG=* next-introspect introspect .
# Check Node.js version
node --version
# Check npm version
npm --versionManual Verification
# Check project structure
find . -name "*.tsx" -o -name "*.ts" -o -name "*.jsx" -o -name "*.js" | head -20
# Check package.json
cat package.json | jq '.dependencies.next'
# Test file access
ls -la app/page.tsx
ls -la pages/index.jsCreate Test Case
# Create minimal test project
mkdir test-project
cd test-project
npm init -y
npm install next react react-dom
mkdir app
echo 'export default function Home() { return <h1>Hello</h1>; }' > app/page.tsx
echo '{"scripts": {"dev": "next dev"}}' > package.json
# Test next-introspect
next-introspect introspect .Getting Help
Issue Reporting
When reporting issues, please include:
-
Version Information:
next-introspect --version node --version npm --version -
Project Information:
ls -la package.json grep -A5 -B5 '"next"' package.json find . -name "app" -o -name "pages" | head -5 -
Command and Error:
# Exact command that failed next-introspect introspect . --format json -
Environment:
- Operating system and version
- Shell being used
- Any relevant environment variables
Common Workarounds
- Use Basic Mode: For performance issues, start with
--mode basic - Use Local Installation: For permission issues, use
npxor local installation - Simplify Configuration: Remove advanced options to isolate problems
- Check File Paths: Ensure all paths are accessible and correct
If you continue to have issues, please check the GitHub repository for existing issues or create a new issue with detailed information.