Skip to content

Instantly share code, notes, and snippets.

@EngineerSmith
Created January 6, 2025 20:29
Show Gist options
  • Save EngineerSmith/fead8f38a5f3c9d35f8960bbd7b6dac4 to your computer and use it in GitHub Desktop.
Save EngineerSmith/fead8f38a5f3c9d35f8960bbd7b6dac4 to your computer and use it in GitHub Desktop.

This is a workaround for an issue in Wiki.js v3-alpha (and likely earlier versions) where a "Cannot find package 'pako'" error occurs when trying to render the page. As discussed in requarks/wiki#7096.

Quick fix

The quickest way to resolve this is to manually install the pako package within the Wiki.js Docker container.

Using docker-compose:

docker-compose exec wiki npm install pako

After running this command, you may need to re-save the affected page to trigger a successful render.

Using docker:

docker exec <id> npm install pako

Replace with the actual ID of your Wiki.js container. After running this command, you may need to re-save the affected page to trigger a successful render.

Persistent Fix

Because the pako package needs to be reinstalled after a docker-compose down operation, a more persistent solution is needed. This involves a bash script and a systemd service (for linux - tested on Ubuntu Server 24)

  1. Create a bash script (e.g. pako_patch.sh) in the same directory as your docker-compose.yml file
    • Write your own bash script, using the suggested command docker-compose exec -T wiki npm install pako, or use the file below which handles retries and basic gotchas.
  2. Create a systemd service (e.g. pako-patch.service) in /etc/systemd/system/
    • Write your own, or use the file below - ensuring you change the directory to yours.
  3. Enable, and start the service
sudo systemctl enable pako-patch.service
sudo systemctl start pako-patch.service
  • The given service runs when the system boots, or if the script failed.

You can always run the bash script manually after recreating the containers with docker-compose up -d.

Notes

This fix was tested on Wiki.js 3.0.0-alpha.386 (the latest alpha release at the time of writing). This workaround is temporary. Once Wiki.js v3 reaches beta or a stable release, this script and service should no longer be necessary, as the issue will likely be resolved upstream. You should then remove the script and disable the service (if you created one).

[Unit]
Description=Run pako patch script for Wiki.Js#3.0.0-alpha
After=network.target docker.service
[Service]
User=root
ExecStart=/bin/bash -c "cd /path/to/your/ && ./pako_patch.sh" # Replace with your own path
Restart=on-failure
[Install]
WantedBy=multi-user.target
#!/bin/bash
echo "Starting pako patch..."
is_container_running(){
local container_id=$(docker-compose ps -q wiki)
if [[ -z "$container_id" ]]; then
return 1
fi
local container_status=$(docker inspect --format='{{.State.Status}}' $container_id)
if [[ "$container_status" == "running" ]]; then
return 0
else
return 1
fi
}
# Check if script is in a directory with docker-compose.yml
if [[ ! -f "docker-compose.yml" ]]; then
echo "Error: docker-compose.yml file not found in the current directory. Script must be ran in the same directory as the wiki's docker compose yaml." >&2
exit 1
fi
# Wait for 'Wiki' container to be running
timeout=30 # Maximum number of attempts
attempts=0
while ! is_container_running; do
if [[ $attempts -ge $timeout ]]; then
echo "Error: Wiki container failed to start within $timeout attempts." >&2
exit 1
fi
echo "Waiting for wiki container to start..."
sleep 1
attempts=$((attempts+1))
done
echo "Installing pako..."
docker-compose exec -T wiki npm install pako > /dev/null 2>&1
echo "Finished pako patch!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment