🐛 "require is not defined" error when spawning Claude Code with version 2.0.0-alpha.83
- Dominant language
- TypeScript
- Stars
- 72.7k
- Forks
- 8.6k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 83
Description
# 🐛 "require is not defined" error when spawning Claude Code with version 2.0.0-alpha.83
## Description
When executing `npx claude-flow swarm` with version `2.0.0-alpha.83`, the system fails to spawn Claude Code with the error `require is not defined` and falls back to the built-in executor. The compiled swarm module is also not found.
## Steps to Reproduce
1. Run `npx claude-flow@alpha swarm "your development task"`
2. System attempts to spawn Claude Code
3. Error occurs and fallback is triggered
## Commands Executed
```
npx claude-flow@alpha swarm "your development task"
npx claude-flow@alpha swarm "your development task" --executor
```
## Error Messages
```
Need to install the following packages:
claude-flow@2.0.0-alpha.83
Ok to proceed? (y)
🐝 Launching Claude Flow Swarm System...
📋 Objective: your development task
🎯 Strategy: auto
🏗️ Mode: centralized
🤖 Max Agents: 5
❌ Failed to spawn Claude Code: require is not defined
Falling back to built-in executor...
📦 Compiled swarm module not found, checking for Claude CLI...
```
## Environment Information
- **claude-flow version**: v2.0.0-alpha.83
- **Node.js version**: v22.18.0
- **npm version**: 10.9.3
- **Operating System**: Linux x64
- **Installation method**: npx
## Expected Behavior
The system should successfully spawn Claude Code and execute the requested development task without errors.
## Actual Behavior
- Claude Code fails to spawn with "require is not defined" error
- System falls back to built-in executor
- Compiled swarm module is not found
- Process cannot proceed with the intended swarm functionality
## Analysis
This error appears to be related to ES modules vs CommonJS compatibility issues. The "require is not defined" error suggests that the code is attempting to use `require()` in a context where only ES module imports are supported, particularly with Node.js v22.18.0.
**Important Note**: Claude Code appears to be properly available since the hive-mind command works correctly:
```
npx claude-flow@alpha hive-mind spawn "build enterprise system" --claude
```
This suggests the issue is specific to the swarm system rather than a general Claude Code integration problem.
## Attempted Solutions
- [x] Tried using `--executor` flag
- [x] Verified claude-flow version (v2.0.0-alpha.83)
- [x] Confirmed Node.js and npm versions
- [x] Verified Claude Code availability (hive-mind command works)
- [ ] Testing with different Node.js versions
## Priority
**High** - This error blocks the primary swarm system functionality while other features (hive-mind) work correctly
## Related Issues
This issue may be related to:
- ES modules compatibility with Node.js v22.18.0 specifically in swarm mode
- Missing compiled swarm module in alpha.83 release
- Swarm-specific Claude Code integration problems (not global Claude Code issues)
**Labels:** `bug`, `alpha-83`, `swarm`, `claude-code-integration`, `node-v22`, `es-modules`, `swarm-specific`
Contributor guide
Research direction
Start by reproducing the failure with `npx claude-flow@alpha swarm "your development task"` on Node.js v22.18.0, then compare it with the working `hive-mind spawn ... --claude` entry point. Trace the swarm startup and Claude Code spawning path, including the compiled swarm module lookup. Done means swarm launches Claude Code without the `require is not defined` error or missing-module fallback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100