This guide helps you resolve common issues when using ZodKit.
- Installation Issues
- Build Issues
- Runtime Errors
- Command-Specific Issues
- Performance Issues
- Getting Help
Problem:
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: typescript@5.x.x
Solution:
# Use npm's legacy peer deps resolver
npm install --legacy-peer-deps
# Or use force (not recommended)
npm install --forceProblem:
Error: Cannot find module 'ts-morph'
Solution:
# Clear npm cache and reinstall
npm cache clean --force
rm -rf node_modules package-lock.json
npm installProblem:
error TS2304: Cannot find name 'z'
Solution: Ensure you have compatible TypeScript version:
npm install typescript@^5.0.0 --save-devProblem:
src/core/schema-stats.ts:100:15 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'ZodSchemaInfo'
Solution:
-
Clean build artifacts:
rm -rf dist npm run build:tsc
-
Check TypeScript configuration:
npx tsc --showConfig
-
Ensure all dependencies are installed:
npm install
Problem:
ERROR in ./src/cli/index.ts
Module not found: Error: Can't resolve 'ts-morph'
Solution:
# Rebuild with clean slate
npm run build:clean
npm run build
# If issue persists, check webpack config
cat webpack.config.js | grep externalsProblem: Build process takes more than 5 minutes or appears to hang.
Solution:
-
Increase Node.js memory:
export NODE_OPTIONS="--max-old-space-size=4096" npm run build
-
Use TypeScript incremental compilation:
npm run dev # Watch mode is faster
Problem:
$ zodkit lint
Error: Cannot find module '/usr/local/lib/node_modules/zodkit/dist/cli/index.js'Solution:
-
Rebuild the project:
npm run build
-
If installed globally, reinstall:
npm uninstall -g zodkit npm install -g zodkit
-
Or use npx:
npx zodkit lint
Problem:
$ zodkit lint
bash: /usr/local/bin/zodkit: Permission deniedSolution:
# Fix permissions
sudo chmod +x /usr/local/bin/zodkit
# Or reinstall without sudo
npm install -g zodkitProblem:
Error: Failed to parse source file
SyntaxError: Unexpected token
Solution:
-
Ensure file is valid TypeScript:
npx tsc --noEmit path/to/file.ts
-
Check for unsupported syntax:
- ZodKit uses ts-morph which may not support all experimental features
- Try simplifying the schema temporarily
-
Skip problematic files:
zodkit lint "src/**/*.ts" "!src/problematic.ts"
Problem:
$ zodkit lint
✓ No issues foundBut you know there are issues.
Solution:
-
Check file patterns:
zodkit lint "src/**/*.schema.ts" --verbose -
Verify schemas are being found:
zodkit check # Should show schema count -
Check if schemas are properly exported:
// Bad - not exported const UserSchema = z.object({...}); // Good - exported export const UserSchema = z.object({...});
Problem: Lint auto-fix modifies code incorrectly.
Solution:
-
Always review changes before accepting:
zodkit lint --fix --dry-run # Preview changes -
Use version control:
git diff # Review changes git checkout -- . # Revert if needed
-
Report the issue with a minimal reproduction case
Problem:
$ zodkit stats
Total schemas: 0Solution:
-
Check file patterns:
zodkit stats "src/**/*.ts" --verbose -
Verify Zod schemas are properly defined:
// Must use z.object, z.array, etc. export const MySchema = z.object({ name: z.string(), });
-
Check for schema naming:
// Schema variables should be exported export const UserSchema = z.object({...}); // ✓ Found const user = z.object({...}); // ✗ Not found
Problem: Bundle sizes seem incorrect or too high.
Solution:
-
Bundle impact is an estimate based on schema complexity
-
Actual sizes may vary depending on:
- Tree-shaking effectiveness
- Bundler configuration
- Zod version
-
Use it for relative comparison, not absolute sizing
Problem: Schema depth or field count doesn't match expectations.
Solution:
-
Check the schema definition:
zodkit stats --verbose # Shows detailed metrics -
Understand depth calculation:
- Counts nested
z.object()andz.array()calls - Does not count method chains like
.optional().nullable()
- Counts nested
-
Field count only works for object schemas:
z.object({ a: z.string() }) // fieldCount: 1 z.array(z.string()) // fieldCount: 0
Problem:
$ zodkit create
# No prompts appear, or terminal hangsSolution:
-
Ensure terminal supports interactivity:
# Test with simple prompt zodkit create --template user --name Test -
Check if stdin is available:
# May not work in some CI environments # Use non-interactive mode zodkit create --template user --name MySchema --output schema.ts
-
Update Node.js to v18+:
node --version # Should be v18.0.0 or higher
Problem: Generated schema has TypeScript errors.
Solution:
- Report the issue with template name and steps to reproduce
- Manually fix generated code
- Consider using a different template as a starting point
Problem:
Error: EACCES: permission denied, open 'schema.ts'
Solution:
# Check directory permissions
ls -la $(dirname schema.ts)
# Create directory if needed
mkdir -p schemas
# Try different output path
zodkit create --output ./schemas/my-schema.tsProblem: Commands take more than 10 seconds to execute.
Solution:
-
Use caching:
zodkit analyze --fast # Uses cached results -
Limit file patterns:
zodkit stats "src/schemas/**/*.ts" # Not "**/*.ts"
-
Exclude large files:
zodkit lint "src/**/*.ts" "!src/generated/**"
Problem:
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Solution:
-
Increase Node.js memory:
export NODE_OPTIONS="--max-old-space-size=4096" zodkit stats
-
Process files in batches:
# Instead of all at once zodkit stats "src/schemas/part1/**/*.ts" zodkit stats "src/schemas/part2/**/*.ts"
-
Use streaming mode (if available):
zodkit analyze --streaming
Problem: Parsing large TypeScript files takes a long time.
Solution:
-
Use
skipFileDependencyResolution:// In zodkit.config.json { "parser": { "skipFileDependencyResolution": true } }
-
Simplify schemas - split large schemas into smaller ones
-
Use progressive loading:
zodkit analyze --progressive
Problem:
$ zodkit lint
# Doesn't use zodkit.config.json settingsSolution:
-
Check config file name and location:
ls zodkit.config.json # Must be in project root -
Validate JSON syntax:
cat zodkit.config.json | jq . # Should parse without errors
-
Use explicit config path:
zodkit lint --config ./path/to/config.json
Problem: Custom linting rules are ignored.
Solution:
-
Check rule configuration:
{ "rules": { "require-description": "error", "no-any-type": "warn" } } -
Ensure rule names are correct (case-sensitive)
-
Check rule severity is not "off":
{ "rules": { "require-description": "off" // ✗ Disabled } }
Causes:
- Schema files not matching pattern
- Schemas not exported
- TypeScript compilation errors
Fix:
# Check what files are being scanned
zodkit check --verbose
# Verify schema export
export const MySchema = z.object({...}); # Must be exportedCauses:
- Complex schema definitions
- Unsupported Zod features
- AST parsing errors
Fix:
# Try with simpler schema
zodkit analyze --mode check # Faster, less analysis
# Check TypeScript compilation
npx tsc --noEmitCauses:
- Invalid schema structure
- Plugin compatibility issues
Fix:
# Skip problematic rules
zodkit lint --severity error # Only run error-level rules
# Update zodkit
npm update zodkit- Check this troubleshooting guide thoroughly
- Search existing issues: https://github.com/JSONbored/zodkit/issues
- Update to latest version:
npm update zodkit
- Try with minimal reproduction:
- Create a small test case
- Isolate the problem
**Environment:**
- ZodKit version: (run `zodkit --version`)
- Node.js version: (run `node --version`)
- npm version: (run `npm --version`)
- Operating System: (e.g., macOS 13.0, Ubuntu 22.04)
**Steps to Reproduce:**
1. Run `zodkit lint src/schema.ts`
2. See error: ...
**Expected Behavior:**
Should lint schema without errors.
**Actual Behavior:**
Gets error: "Cannot find module..."
**Minimal Reproduction:**
```typescript
// src/schema.ts
import { z } from 'zod';
export const MySchema = z.object({
name: z.string(),
});Additional Context:
- Tried solutions: X, Y, Z
- Workarounds: None found
### Getting Quick Help
- **Discord/Slack**: Check project README for community links
- **GitHub Discussions**: For questions and discussions
- **Stack Overflow**: Tag with `zodkit` and `zod`
- **Twitter**: Tweet @zodkit_cli (if available)
### Professional Support
For enterprise support, contact: support@zodkit.dev
---
**Didn't find your issue?** [Open a new issue](https://github.com/JSONbored/zodkit/issues/new) with details!