{"id":18474,"library":"koa-pug","title":"Koa-pug","description":"Koa-pug is a Pug (formerly Jade) template engine middleware for Koa (v1 and v2) JavaScript web frameworks. Current stable version is 5.1.1, released in 2019, with infrequent updates (last commit 2019). It integrates Pug templates into Koa by binding ctx.render() and supports custom view paths, global helpers via helperPath, and standalone rendering. Key differentiators: seamless Koa integration, helper auto-loading from directories, and Pug@3 support. Alternatives like @ladjs/koa-pug-view are more actively maintained.","status":"maintenance","version":"5.1.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install koa-pug","lang":"bash","label":"npm"},{"cmd":"yarn add koa-pug","lang":"bash","label":"yarn"},{"cmd":"pnpm add koa-pug","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for template compilation","package":"pug","optional":false},{"reason":"Optional peer dependency; required only for Koa integration","package":"koa","optional":true}],"imports":[{"note":"CommonJS only; package does not provide ESM exports. Use require().","wrong":"import Pug from 'koa-pug'","symbol":"default","correct":"const Pug = require('koa-pug')"},{"note":"Default export only; no named exports. Works with ESM loader but required CJS module.","wrong":"import { Pug } from 'koa-pug'","symbol":"default","correct":"import Pug from 'koa-pug'"},{"note":"Dynamic import returns default export as module.default; destructure not needed.","wrong":"const { Pug } = await import('koa-pug')","symbol":"default","correct":"const Pug = await import('koa-pug')"}],"quickstart":{"code":"const Koa = require('koa');\nconst Pug = require('koa-pug');\nconst path = require('path');\n\nconst app = new Koa();\nconst pug = new Pug({\n  viewPath: path.resolve(__dirname, './views'),\n  locals: { title: 'Hello' },\n  app: app\n});\n\napp.use(async ctx => {\n  await ctx.render('index', { message: 'World' });\n});\n\napp.listen(3000);","lang":"javascript","description":"Sets up a Koa server with Pug template rendering using koa-pug middleware."},"warnings":[{"fix":"Consider using @ladjs/koa-pug-view for active support.","message":"The package is in maintenance mode; no active development since 2019.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Upgrade Node.js to >=10 and install Pug@3.","message":"Version 5.x drops support for Node <10 and requires Pug@3.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Pass { app: app } in options or call pug.use(app).","message":"The `app` option must be passed to constructor to bind ctx.render(); otherwise, you must call pug.use(app) after instantiation.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use PascalCase or camelCase in filenames to avoid naming conflicts.","message":"When using helperPath, the module filename is converted to camelCase for the helper name. For example, 'format-date.js' becomes 'formatDate'.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"new Pug({ app: app }) or pug.use(app);","cause":"Missing `app` option or `pug.use(app)` not called; ctx.render not bound.","error":"TypeError: render is not a function"},{"fix":"npm install pug --save","cause":"Pug package is not installed as a dependency.","error":"Error: Cannot find module 'pug'"},{"fix":"Ensure viewPath is correct (defaults to process.cwd()) and template exists.","cause":"Template file not found in viewPath or incorrect path.","error":"Error: Could not find template 'index'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}