I am trying to use Nunjucks as a template engine from Express. I did this:
var express = require('express');
var nunjucks = require('nunjucks');
var path = require('path');
var bodyParser = require('body-parser');
var load = require('express-load');
var fs = require("fs");
var app = express();
app.set('views', path.join(__dirname, 'views'));
var env = nunjucks.configure(app.get('views'), {
autoescape: true,
express: app
});
app.set('view engine', 'html');
But above code gives this error:
Template render error: compileExtends: cannot extend multiple times
at Error.exports.TemplateError (C:\my\nodejs\projects\\node_modules\nunjucks\src\lib.js:49:19)
at Object.extend.fail (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:49:15)
at Object.extend.compileExtends (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:983:18)
at Object.extend.compile (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:1083:22)
at Object.extend._compileChildren (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:139:18)
at Object.extend.compileRoot (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:1050:14)
at Object.extend.compile (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:1083:22)
at Object.module.exports.compile (C:\my\nodejs\projects\\node_modules\nunjucks\src\compiler.js:1118:11)
at Obj.extend._compile (C:\my\nodejs\projects\\node_modules\nunjucks\src\environment.js:414:35)
at Obj.extend.compile (C:\my\nodejs\projects\\node_modules\nunjucks\src\environment.js:403:18)
Please tell me how to fix this ?
A rich, high-performance JavaScript templating language, supported by all modern browsers. Nunjucks is customizable with extensions and filters; it offers inheritance, asynchronous control, autoescaping and other features. It also supports any version of Node.
Nunjucks is a templating engine for JavaScript, inspired by Jinja. It has many nifty features that make templating really nice: Variables declaration. Built-in filters.
I just setup nunjucks using the default way:
const express = require('express');
const nunjucks = require('nunjucks');
const app = express();
app.engine('html', nunjucks.render);
app.set('view engine','html');
app.set('views', globals.viewsDirectory);
"express": "4.16.4", "nunjucks": "^3.2.3",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With