Registry /
web-framework / vite-plugin-twig-loader
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default (vite-plugin-twig-loader)
✓ import twig from 'vite-plugin-twig-loader'
✗ const twig = require('vite-plugin-twig-loader')
ESM-only? Imports default export; works with both ESM and CJS in Vite config
default (twig template import)
✓ import template, { path, ctx, globals, settings } from './template.twig'
✗ import template from './template.twig'
Default export is the compiled template string; named exports path, ctx, globals, settings are available for advanced usage
Twig from twig.js
✓ import Twig from 'twig'
✗ const Twig = require('twig')
CommonJS vs ESM: 'twig' package ships CJS; use require() in Node.js scripts, or configure Vite to handle CJS
Shows Vite config setup and how to import a .twig file and use it with twig.js for rendering.
// vite.config.js
import { defineConfig } from 'vite';
import twig from 'vite-plugin-twig-loader';
export default defineConfig({
plugins: [
twig({
// optional: filters: { myFilter: (val) => val.toUpperCase() },
// optional: functions: { myFunction: (arg) => `Hello ${arg}` },
// optional: globals: { siteName: 'My Site' },
// optional: settings: { cache: false }
})
]
});
// Then in any module:
import cardTemplate, { path, ctx, globals, settings } from './card.twig';
console.log('Template string:', cardTemplate);
console.log('Source path:', path);
console.log('Context (raw template content):', ctx);
console.log('Globals:', globals);
console.log('Settings:', settings);
// To render with twig.js:
import Twig from 'twig';
const output = Twig.twig({ data: ctx }).render({ title: 'Hello', body: 'World' });
Errors
Common errors & fixes
Cannot find module 'vite-plugin-twig-loader'
Package not installed or version mismatch.
fixnpm install vite-plugin-twig-loader --save-dev
Cannot find module 'twig'
Peer dependency 'twig' not installed.
fixnpm install twig --save-dev
Failed to load .twig file: 'You may need an additional loader'
Plugin not added to Vite config or not properly configured.
fixAdd 'twig()' to plugins array in vite.config.js and restart dev server.
Audit
Dependencies
twigrequiredrequired peer dependency for Twig templating engine