mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 635 forks source link

_Loader.call is not a function under Bun 0.1.8 #1412

Open robogeek opened 1 year ago

robogeek commented 1 year ago

While testing various modules on Bun, I came across a failure with Nunjucks. With a simple inline template and code that runs fine with Nunjucks on Node.js, it fails with the above message.

import nunjucks from 'nunjucks';
let people = ['geddy', 'neil', 'alex'];

const template = nunjucks.compile('Hello {{ username }}');
console.log(template);

console.log(nunjucks.renderString('{{ people | join(", ") }}', { people: people }));

console.log(nunjucks.renderString(`
    <ul id="products">
    {% for person in people %}
        <li>{{ person }}</li>
    {% endfor %}
    </ul>
    `, { people: people }));

Simple. With Node.js, the output is what you'd expect from the templates. It was interesting to look at the compiled template object after having used Nunjucks for a couple years.

$ bun nunjucks.mjs 
20 |   _inheritsLoose(FileSystemLoader, _Loader);
21 | 
22 |   function FileSystemLoader(searchPaths, opts) {
23 |     var _this;
24 | 
25 |     _this = _Loader.call(this) || this;
                ^
TypeError: _Loader.call is not a function. (In '_Loader.call(this)', '_Loader.call' is undefined)
      at new FileSystemLoader (/home/david/Projects/akasharender/akashacms-perftest/node_modules/nunjucks/src/node-loaders.js:25:12)
      at configure (/home/david/Projects/akasharender/akashacms-perftest/node_modules/nunjucks/index.js:41:21)
      at compile (/home/david/Projects/akasharender/akashacms-perftest/node_modules/nunjucks/index.js:82:6)
      at /home/david/Projects/akasharender/akashacms-perftest/bench/nunjucks.mjs:5:17

I inserted to console.log statements:

UltiRequiem commented 1 year ago

This is bun error, not a nunjucks one.