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

renderTemplate fails with simple example (global versus local install) #2100

Open
cfjedimaster opened this issue Nov 17, 2021 · 18 comments
Open
Assignees

Comments

@cfjedimaster
Copy link

Describe the bug
I'm trying this simple example of the renderTemplate feature (using beta8):

{% assign name = "Ray" %}
Hello World, and {{ name }}

<p>

{% renderTemplate "md" %}
# I am a title

* I am a list
* I am a list
{% endrenderTemplate %}

And when I run eleventy, I get:

ray@Hoth:~/projects/testingzone/eleventybeta$ eleventy
[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] > Having trouble rendering liquid template ./index.liquid

`TemplateContentRenderError` was thrown
[11ty] > Cannot read property 'includes' of undefined, file:./index.liquid, line:8, col:1

`RenderError` was thrown
[11ty] > Cannot read property 'includes' of undefined

`TypeError` was thrown:
[11ty]     TypeError: Cannot read property 'includes' of undefined
        at new TemplateRender (/home/ray/projects/testingzone/eleventybeta/node_modules/@11ty/eleventy/src/TemplateRender.js:31:23)
        at Object.render (/home/ray/projects/testingzone/eleventybeta/node_modules/@11ty/eleventy/src/Plugins/RenderPlugin.js:31:12)
        at Object.renderStringShortcodeFn (/home/ray/projects/testingzone/eleventybeta/node_modules/@11ty/eleventy/src/Plugins/RenderPlugin.js:224:27)
        at Object.render (/home/ray/projects/testingzone/eleventybeta/node_modules/@11ty/eleventy/src/Plugins/RenderPlugin.js:116:40)
        at async Template._render (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/TemplateContent.js:315:22)
        at async Template.getTemplateMapContent (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/Template.js:1003:19)
        at async TemplateMap.populateContentDataInMap (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:459:39)
        at async TemplateMap.cache (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/TemplateMap.js:360:5)
        at async TemplateWriter._createTemplateMap (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:242:5)
        at async TemplateWriter.generateTemplates (/home/ray/.nvm/versions/node/v14.18.0/lib/node_modules/@11ty/eleventy/src/TemplateWriter.js:275:5)
[11ty] Wrote 0 files in 0.03 seconds (v1.0.0-beta.8)

To Reproduce
See above. :)

Expected behavior
I'd expect the block to render from Markdown.

Environment:

  • OS and Version: [e.g. Windows/Mac/Linux] Windows/WSL
  • Eleventy Version [via eleventy --version or npx @11ty/eleventy --version] v1.0.0-beta.8
@cfjedimaster
Copy link
Author

So this is interesting. I have beta8 installed globally. I also have it installed in my test folder. If I run eleventy, I get the error above. If I specifically use the local copy with npx eleventy, it runs fine. Both output the exact same version.

@zachleat
Copy link
Member

image

image

Hmmmmmmmmm.

Is that the full contents of the file?

@zachleat
Copy link
Member

We do have an automated test suite for these plugins that does run on Windows too https://github.com/11ty/eleventy/actions/runs/1472651558

@cfjedimaster
Copy link
Author

Can you try where Eleventy is not in node_modules but installed globally?

@zachleat
Copy link
Member

Had to get my $NODE_PATH going again for global node_modules but I got the same successful result 😭

@zachleat
Copy link
Member

zachleat commented Nov 18, 2021

Sorry to do this but can you make a reduced test case repo that shows this locally for you?

I don’t think I’m seeing all the variables things at play here

@cfjedimaster
Copy link
Author

Not a problem - will do so but may take a day.

@peerreynders
Copy link

peerreynders commented Nov 19, 2021

Reduced test case repo

Here there are no errors - instead the template render simply stops.

Upon npm run build the template src/index.njk

{% extends "base.njk" %}

{% set content %}
<section id="book-title">
{% renderTemplate "md" %}
# Title of Book

by Author

{% endrenderTemplate %}
</section>
{% endset %}

results in the following markup dist/index.html:

<!DOCTYPE html>
<html lang="en">
  <body>
    <div id="page">
      
<section id="book-title">
    </div>
  </body>
</html>

i.e the template fails to render past the point of the renderTemplate "md".

Platform:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

$ node -v
v16.13.0

$ npm -v
8.1.0
$ 

FYI: https://github.com/11ty/eleventy/blob/master/src/TemplateRender.js#L29

    console.log('\ninputDir', inputDir);
    this.inputDir = inputDir ? inputDir : this.config.dir.input;
    console.log('this.inputDir', this.inputDir);

    this.includesDir = TemplatePath.join(
      this.inputDir,
      this.config.dir.includes
    );
    console.log('includesDir:', this.includesDir);

results in

$ npm run build

> [email protected] build
> npx @11ty/eleventy


inputDir src
this.inputDir src
includesDir: src/_includes

inputDir src/_includes
this.inputDir src/_includes
includesDir: src/_includes/_includes
[11ty] Writing dist/index.html from ./src/index.njk
[11ty] Wrote 1 file in 0.08 seconds (v1.0.0-beta.8)

So that second TemplateRender instance is provided with the includes path as the input path.

@cfjedimaster
Copy link
Author

So to be clear, you see an error (template not rendering), but not the same issue in console as me? Also, do you see a difference between global eleventy versus local?

@peerreynders
Copy link

Given I can get it to fail locally I never explored a global installation.

However I used your error message to zero in on the faulty includesDir setting of that second TemplateRender instance - which likely is responsible for the failure.

Too be clear I'm not familiar with the code that creates TemplateRender - the first question that comes to my mind is why are two instances created when there is only one renderTemplate render.

The difference between "build error" and "no build error" may simply be a manifestation of "liquid" vs "nunjucks" responding to the same root cause.

@zachleat zachleat self-assigned this Nov 19, 2021
@zachleat
Copy link
Member

Awesome, thank you for a test case—lookin’

@zachleat
Copy link
Member

Couple of things came from this issue. We were absolutely passing in the wrong directory there to Template Render. That fix will go up with Beta.9

The other thing happening here is a Nunjucks specific issue with nested async shortcodes. Work in progress is happening here for that #1749

@cfjedimaster
Copy link
Author

This still doesn't sound exactly like my issue, but I'm going to wait and test again in 9. :)

@peerreynders
Copy link

Looks like I'll be using the following for a while

{# src/index.njk #}
{% extends "base.njk" %}

{% set content %}
<section id="book-title">
{% renderTemplateMd %}
# Title of Book

by Author

{% endrenderTemplateMd %}
</section>
{% endset %}
// .eleventy.js
//
const markdownIt = require('markdown-it');

const md = markdownIt({
  html: true,
});

function renderMd(content, inline) {
  return inline ? md.renderInline(content) : md.render(content);
}

const dir = {
  input: 'src',
  includes: '_includes',
  output: 'dist',
};

module.exports = function(config) {
  config.addPairedShortcode("renderTemplateMd", renderMd);

  return {
    dir
  };
};

resulting in

<!DOCTYPE html>
<html lang="en">
  <body>
    <div id="page">
      
<section id="book-title">
<h1>Title of Book</h1>
<p>by Author</p>

</section>
    </div>
  </body>
</html>

@zachleat
Copy link
Member

zachleat commented Nov 20, 2021

For the record @peerreynders I believe your issue is separate @cfjedimaster’s original issue. I filed yours at #2108. Specifically note this comment: #2108 (comment)

@zachleat
Copy link
Member

My suspicion here @cfjedimaster is that this might be mixing and matching a global with a local installation?

Like, maybe you’re executing a global Eleventy but it’s requiring from a local Eleventy. And the versions are different?

What’s your NODE_PATH? Are there local installations of Eleventy at play?

@zachleat zachleat changed the title renderTemplate fails with simple example renderTemplate fails with simple example (global versus local install) Nov 20, 2021
@cfjedimaster
Copy link
Author

cfjedimaster commented Nov 30, 2021

Both the local Eleventy and global are the same version version. NODE_PATH is not defined.

@zachleat zachleat added the feature: 🪢 render plugin The Render plugin label Dec 8, 2022
@tfrancart
Copy link

tfrancart commented Feb 27, 2024

FYI, I stumbled on the same issue as originally reported when using eleventy Github action while my local build works. I use v2.0.1 locally. The Github action is doing a global install of eleventy, but then also runs an npm install, which will install a local eleventy. I use Nunjucks.

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

No branches or pull requests

4 participants