Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple errors with Nunjucks import #69

Closed
jvolker opened this issue Nov 6, 2016 · 8 comments
Closed

Multiple errors with Nunjucks import #69

jvolker opened this issue Nov 6, 2016 · 8 comments

Comments

@jvolker
Copy link

jvolker commented Nov 6, 2016

Using the Metalsmith static-site-example I ran into two issues with Nunjucks import.

I added static-site/layouts/macros.html and try to import it for further usage from within index.md

{% import "macros.html" as macros %} throws:

Template render error: (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/src/index.html)
  Error: template names must be a string: undefined
    at Object.exports.prettifyError (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/lib.js:34:15)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:486:31
    at root [as rootRenderFunc] (eval at <anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:565:24), <anonymous>:26:3)
    at Obj.extend.render (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:479:15)
    at Transformer.render (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/node_modules/jstransformer/index.js:289:25)
    at renderFile (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/lib/render-file.js:48:31)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:38:25
    at Array.forEach (native)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:34:24)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:45:19)
    at next (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/lib/index.js:85:20)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:121:18
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:52:16
    at done (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:246:17)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:44:16
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/lib/index.js:143:9
make: *** [build] Error 1

{% import "../layouts/macros.html" as macros %} throws:

Template render error: (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/src/index.html) [Line 23, Column 19]
  expected name as lookup value, got .
    at Object.exports.prettifyError (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/lib.js:34:15)
    at Obj.extend.init (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:437:27)
    at new new_cls (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/object.js:46:28)
    at Object.module.exports.compile (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/index.js:64:12)
    at Object.exports.compile (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/index.js:41:27)
    at Transformer.render (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/node_modules/jstransformer/index.js:288:44)
    at renderFile (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/lib/render-file.js:48:31)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:38:25
    at Array.forEach (native)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:34:24)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:45:19)
    at next (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/lib/index.js:85:20)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:121:18
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:52:16
    at done (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:246:17)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:44:16
make: *** [build] Error 1

I could get around this by adding a variable to the YAML front matter like this: pathToMacros : ../layouts/macros.html and called it using that variable {% import pathToMacros as macros %}

But then I end up with the following template not found error:

Template render error: (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/src/index.html)
  Template render error: (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/src/index.html)
  Error: template not found: /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/layouts/macros.html
    at Object.exports.prettifyError (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/lib.js:34:15)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:486:31
    at root [as rootRenderFunc] (eval at <anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:565:24), <anonymous>:26:3)
    at Obj.extend.render (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/jstransformer-nunjucks/node_modules/nunjucks/src/environment.js:479:15)
    at Transformer.render (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/node_modules/jstransformer/index.js:289:25)
    at renderFile (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/lib/render-file.js:48:31)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:38:25
    at Array.forEach (native)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-in-place/index.js:34:24)
    at Ware.<anonymous> (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:45:19)
    at next (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/lib/index.js:85:20)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith/node_modules/ware/node_modules/wrap-fn/index.js:121:18
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:52:16
    at done (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:246:17)
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/node_modules/async/lib/async.js:44:16
    at /Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/node_modules/metalsmith-layouts/lib/index.js:143:9
make: *** [build] Error 1

Not sure where the issue lies: metalsmith-in-place, jstransformer-nunjucks, Nunjucks or even my own fault?

Thanks for help in advance!

@ismay
Copy link
Member

ismay commented Nov 7, 2016

It's difficult for me to say exactly what's happening here without an example repo. If you could create a public repo that recreates the error above I can take a look at it.

@ismay
Copy link
Member

ismay commented Nov 7, 2016

I'm closing this for now by the way, as it doesn't seem to be a bug in in-place. However, feel free to keep the discussion going and point me to a repo if it's up.

@ismay ismay closed this as completed Nov 7, 2016
@jvolker
Copy link
Author

jvolker commented Nov 7, 2016

I put it up here: https://github.com/jvolker/Metalsmith-in-place-test
I tried to add the macro in src/index.md

Thanks a lot for looking into it!

@ismay
Copy link
Member

ismay commented Nov 9, 2016

No problem. After taking a look this looks like it's related to jstransformers/jstransformer-nunjucks#10. So this seems to be an issue with the particular jstransformer you're using. If not, let me know.

@jvolker
Copy link
Author

jvolker commented Nov 10, 2016

I'm not sure. The symptoms of the third error described above seem to be very similar.
Though jstransformers/jstransformer-nunjucks#10 reads:

Demonstrates how includes work for files on the same level, or below it, but fail for includes of files located above the parent.

And in my test repo the template files are on the same level already. So I'm not sure if it actually is related.

And in any case I also had Error: template names must be a string: undefined and Template render error: (/Users/js/Downloads/metalsmith-test/metalsmith/examples/static-site/src/index.html) [Line 23, Column 19] expected name as lookup value, got . as described above. These errors were not mentioned in jstransformers/jstransformer-nunjucks#10.

@ismay
Copy link
Member

ismay commented Nov 10, 2016

And in my test repo the template files are on the same level already. So I'm not sure if it actually is related.

Not really. The file from which you're calling macros isn't in the same folder as the macros. Try moving everything into src, see if that makes a difference.

But regardless, I don't see how this is an error with metalsmith-in-place. You're experiencing problems with a specific templating engine. If there is a bug in in-place let me know, but that does not seem to be the case.

@jvolker
Copy link
Author

jvolker commented Nov 12, 2016

Not really. The file from which you're calling macros isn't in the same folder as the macros. Try moving everything into src, see if that makes a difference.

Yes, you're right. This made a difference and seems to be a bug in the transformer. Thanks again!

I again tried to figure out, where those other errors were coming from. Fixed it now!
I was basically running in-place after the Markdown plugin. The Markdown plugin had already converted the quotation mark for example in {{ "some string" }} to {{ &quot;some string&quot; }}. I switch this so in-place is running before Markdown. Additionally I had to make sure all files would have the *.nunjucks extension so the transformer would actually be applied which is not the case with *.md extensions.

@ismay
Copy link
Member

ismay commented Nov 12, 2016

Yes, you're right. This made a difference and seems to be a bug in the transformer. Thanks again!

👍 You're welcome, glad that solved it. So yeah, that's the bug I ran into as well, weird. Good that it's all working well now. Hopefully the bug in the jstransformer will be solved soon, would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants