1

I have a fairly large Metalsmith project using Nunjucks for templating (i.e. using metalsmith-in-place, which uses jstransformer-nunjucks):

const Metalsmith       = require('metalsmith'),
      inplace          = require('metalsmith-in-place');

Metalsmith(__dirname)
  .metadata(metadata)
  .source('./src')
  .destination('./build')
  .use(inplace({
    engineOptions: {
      root: path.join(__dirname, 'src')
    }
  }))
  .build(function(err) {
    if (err) {
      throw err;
    }
  });

When I run my build script, I get a template error from a template with an "unknown path":

> project@0.4.0 build ~/project
> node build.js

~/project/build.js:155
          throw err;
          ^

Template render error: (unknown path) [Line 13, Column 6]
  unknown block tag: greetingSection
    at Object._prettifyError (~/project/node_modules/nunjucks/src/lib.js:36:11)
    at Template.init (~/project/node_modules/nunjucks/src/environment.js:515:19)
    at Template.Obj (~/project/node_modules/nunjucks/src/object.js:64:15)
    at new Template (~/project/node_modules/nunjucks/src/environment.js:482:18)
    at Object.compile (~/project/node_modules/nunjucks/index.js:85:12)
    at Object.exports.compile (~/project/node_modules/jstransformer-nunjucks/index.js:50:29)
    at Transformer.render (~/project/node_modules/jstransformer/index.js:288:44)
    at resolve (~/project/node_modules/metalsmith-in-place/lib/index.js:60:33)
    at new Promise (<anonymous>)
    at render (~/project/node_modules/metalsmith-in-place/lib/index.js:29:10)

I have no idea which of my many Nunjucks files is causing the error. How to I get metalsmith-in-place to give me the path of the file causing the issue?

jhx4mp
  • 21
  • 4
  • I'd say it has something to do with `unknown block tag: greetingSection` – James Khoury Mar 19 '19 at 10:05
  • Agreed, but almost all of my template files use that custom `{{ greetingSection() }}` macro. Searching through all of my Nunjucks files to find the one error isn't practical, which is why I need Metalsmith to give me the actual file path which has the mistake. – jhx4mp Mar 19 '19 at 14:20
  • This isn't a fix but you should be able to get some details in the `build()` if you add a second argument `files`. – James Khoury Mar 23 '19 at 23:55

0 Answers0