Common Issues
This guide covers the most frequently encountered issues when using Petk and provides step-by-step solutions to resolve them.
Installation Issues​
Issue: command not found: petk
​
Problem: After installing Petk, the command is not recognized.
Solutions:
-
Check if Petk is installed globally:
npm list -g petk
# or
pnpm list -g petk -
Reinstall Petk globally:
npm install -g petk
# or
pnpm install -g petk -
Check your PATH environment variable:
echo $PATH
Make sure your global npm/pnpm bin directory is included.
-
Use npx as an alternative:
npx petk --version
Issue: Permission denied during installation​
Problem: Getting permission errors when installing globally.
Solutions:
-
Use a Node version manager (recommended):
# Install nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install latest Node.js
nvm install node
nvm use node -
Configure npm to use a different directory:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile
source ~/.profile -
Use sudo (not recommended):
sudo npm install -g petk
Processing Issues​
Issue: Template directives not being processed​
Problem: Petk directives like {petk:include}
are not being processed.
Diagnosis:
# Check if the file is being recognized
petk validate your-file.md
# Run with verbose output
petk process your-file.md --verbose
Solutions:
-
Check directive syntax:
<!-- Correct -->
```{petk:include}
path: header.md
```
<!-- Incorrect -->
```{petk:include}
path: header.md
```
```{petk:include}
path: header.md
``` -
Verify file paths are correct:
<!-- Use relative paths -->
```{petk:include}
path: ./components/header.md
```
<!-- Use absolute paths from project root -->
```{petk:include}
path: /templates/shared/footer.md
``` -
Check file encoding:
file your-file.md
# Should show: UTF-8 Unicode text
Issue: Include files not found​
Problem: Getting "file not found" errors for included files.
Solutions:
-
Check current working directory:
pwd
ls -la -
Use absolute paths:
```{petk:include}
path: /full/path/to/file.md
``` -
Set base directory in configuration:
// petk.config.js
module.exports = {
baseDir: './src',
// Other configuration...
}; -
Verify file permissions:
ls -la path/to/included/file.md
Issue: Slow processing performance​
Problem: Petk takes a long time to process files.
Solutions:
-
Use exclude patterns:
petk process ./docs/ --exclude "**/node_modules/**" --exclude "**/draft/**"
-
Process specific file types only:
petk process ./docs/ --include "**/*.md"
-
Enable caching:
// petk.config.js
module.exports = {
cache: {
enabled: true,
directory: './.petk-cache'
}
}; -
Check for circular includes:
petk validate ./docs/ --check-circular
Configuration Issues​
Issue: Configuration file not being loaded​
Problem: Custom configuration is not being applied.
Diagnosis:
# Check which config file is being used
petk --verbose process example.md
Solutions:
-
Verify configuration file name and location:
✓ petk.config.js (project root)
✓ petk.config.json (project root)
✓ .petkrc (project root)
✓ package.json (petk field) -
Check configuration syntax:
# For JavaScript config
node -c petk.config.js
# For JSON config
json_verify < petk.config.json -
Specify config file explicitly:
petk process example.md --config ./path/to/config.js
Issue: Invalid configuration values​
Problem: Configuration values are not being accepted.
Solutions:
-
Validate configuration against schema:
petk config validate
-
Check configuration documentation:
petk config --help
-
Use minimal configuration:
// petk.config.js
module.exports = {
input: './src',
output: './dist'
};
Format Conversion Issues​
Issue: YAML conversion produces invalid output​
Problem: Converting Markdown to YAML creates malformed YAML.
Solutions:
-
Validate YAML output:
petk convert input.md output.yaml
yaml-lint output.yaml -
Use schema validation:
petk convert input.md output.yaml --schema schema.json
-
Check for special characters:
<!-- Problematic -->
title: My Title: With Colons
<!-- Fixed -->
title: "My Title: With Colons" -
Use explicit format specification:
petk convert --from markdown --to yaml input.md output.yml
Issue: Markdown formatting lost during conversion​
Problem: Converting from other formats to Markdown loses formatting.
Solutions:
-
Use preserve-structure option:
petk convert input.yaml output.md --preserve-structure
-
Check input format:
petk convert --from yaml --to markdown input.yml output.md
-
Validate input format:
petk validate input.yml
Development Server Issues​
Issue: Development server won't start​
Problem: petk serve
command fails to start.
Solutions:
-
Check if port is available:
lsof -i :3000
# or
netstat -tlnp | grep :3000 -
Use different port:
petk serve --port 8080
-
Check file permissions:
ls -la ./
-
Clear cache:
rm -rf ./.petk-cache
petk serve
Issue: Live reload not working​
Problem: Changes to files don't trigger automatic reload.
Solutions:
-
Enable live reload explicitly:
petk serve --livereload
-
Check file watch limits (Linux):
cat /proc/sys/fs/inotify/max_user_watches
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p -
Use polling mode:
petk serve --poll
Template Engine Issues​
Issue: Variables not being substituted​
Problem: Template variables like {{variable}}
are not being replaced.
Solutions:
-
Check variable syntax:
<!-- Correct -->
{{site.title}}
<!-- Incorrect -->
{site.title}
{{ site.title }} -
Define variables in configuration:
// petk.config.js
module.exports = {
variables: {
site: {
title: 'My Site',
url: 'https://example.com'
}
}
}; -
Use environment variables:
PETK_SITE_TITLE="My Site" petk process template.md
Issue: Circular dependency in includes​
Problem: Files include each other, creating an infinite loop.
Diagnosis:
petk validate ./templates/ --check-circular
Solutions:
-
Identify circular dependencies:
petk analyze dependencies ./templates/
-
Restructure includes:
<!-- Instead of mutual includes, use a common base -->
<!-- base.md -->
```{petk:include}
path: header.md
```
```{petk:include}
path: content.md
```
```{petk:include}
path: footer.md
``` -
Use conditional includes:
```{petk:include}
path: header.md
if: !included.header
```
Getting Help​
If you're still experiencing issues:
-
Check the GitHub Issues: https://github.com/mihazs/petk/issues
-
Enable debug logging:
PETK_LOG_LEVEL=debug petk process your-file.md
-
Create a minimal reproduction:
petk init minimal-repro
cd minimal-repro
# Add your problematic file
# Test the issue -
Join our community:
-
Report a bug:
- Include Petk version:
petk --version
- Include Node.js version:
node --version
- Include operating system details
- Provide minimal reproduction steps
- Include error messages and logs
- Include Petk version:
Prevention Tips​
-
Always validate files before processing:
petk validate ./templates/ && petk process ./templates/
-
Use version control:
git add .
git commit -m "Before Petk processing"
petk process ./docs/ -
Test with small files first:
echo "# Test" > test.md
petk process test.md -
Keep Petk updated:
npm update -g petk
-
Use configuration files for complex setups:
// petk.config.js - Document your configuration
module.exports = {
// Clear, documented configuration
input: './src',
output: './dist',
// ... other options
};