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

If folder named _data/content exists 11ty 2 fails to build #2824

Closed
Pezmc opened this issue Feb 23, 2023 · 5 comments
Closed

If folder named _data/content exists 11ty 2 fails to build #2824

Pezmc opened this issue Feb 23, 2023 · 5 comments
Labels
duplicate error-messaging feature: 🏔 data cascade Issues related to the Data Cascade feature

Comments

@Pezmc
Copy link

Pezmc commented Feb 23, 2023

Operating system

macOS Ventura 13.2.1

Eleventy

2.0.0

Describe the bug

If any data file exists under the directory name content e.g. _data/content/my-file.json 11ty fails to build, full error below. A minimum reproduction to show the error can be found at: https://github.com/Pezmc/11ty-data-content-issue

My understanding from debugging so far is that the TemplateLayout parsing tries to set data.content but that is declared with only a getter (i.e. read only). It seems likely that the _data dir having a directory named content, which is exposed on the page object, is overlapping with the setting of the page content.

This was not an issue with 11ty <2.0

Error stack trace:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble writing to "_site/some-url" from "./index.md" (via EleventyTemplateError)
[11ty] 2. Cannot assign to read only property 'content' of object '#<Object>' (via TypeError)
[11ty]
[11ty] Original error stack trace: TypeError: Cannot assign to read only property 'content' of object '#<Object>'
[11ty]     at Function.augmentDataWithContent (~/Git/11ty/node_modules/@11ty/eleventy/src/TemplateLayout.js:222:22)
[11ty]     at TemplateLayout.render (~/Git/11ty/node_modules/@11ty/eleventy/src/TemplateLayout.js:243:29)
[11ty]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[11ty]     at async Template.renderPageEntry (~/Git/11ty/node_modules/@11ty/eleventy/src/Template.js:793:17)
[11ty]     at async ~/Git/11ty/node_modules/@11ty/eleventy/src/Template.js:822:21
[11ty]     at async Promise.all (index 0)
[11ty]     at async Promise.all (index 1)
[11ty]     at async Eleventy.executeBuild (~/Git/11ty/node_modules/@11ty/eleventy/src/Eleventy.js:1160:13)
[11ty] Wrote 0 files in 0.04 seconds (v2.0.0)

Reproduction steps

  1. Have a 2.0.0 project
  2. Create a json file under _data/content/any-name.json
  3. Have a markdown file that uses manually created pagination
  4. Run npx @11ty/eleventy

Expected behavior

Short term fix: Rename the content folder to side-step the issue e.g. _data/my-content

Expected behaviour from 11ty: Either throw a clear error if a folder named content (and perhaps other protected internal names) is present; or guard against this happening and allow the _data tags to overlap with the internal props on the page object.

Reproduction URL

https://github.com/Pezmc/11ty-data-content-issue

Screenshots

No response

Pezmc added a commit to FlowFuse/website that referenced this issue Feb 23, 2023
@bobmonsour
Copy link

I can verify that renaming the directory to something other than "content" works fine. Leads me to assume that "content" is a reserved word of some sort in eleventy.

@pdehaan
Copy link
Contributor

pdehaan commented Feb 24, 2023

Yeah, content is a special name in the bowels of Eleventy. And just because I always forget all the properties on items in a collection, here's my handy cheat-sheet from a sample project I had locally:

// index.11tydata.js
const { inspect } = require("node:util");

module.exports = {
  eleventyComputed: {
    debug(data) {
      const p = data.collections.all.at(0);
      if (p) console.log(inspect(p, {sorted: true, depth: 0}));
      return "";
    }
  }
};

OUTPUT

{
  content: [Getter],
  data: [Object],
  date: 2022-06-14T00:00:00.000Z,
  filePathStem: '/news/2022-06-14/index',
  fileSlug: '2022-06-14',
  inputPath: './src/news/2022-06-14/index.md',
  outputPath: 'www/news/2022-06-14/index.html',
  page: [Object],
  template: [Template],
  templateContent: [Getter/Setter],
  url: '/news/2022-06-14/'
}

@j-f1
Copy link
Contributor

j-f1 commented Feb 24, 2023

It would be nice to have Eleventy detect situations like that and give a clear error message.

@zachleat
Copy link
Member

This is filed at #1173! Please subscribe over there!

@zachleat
Copy link
Member

Fixed by #3251 Shipping with 3.0.0-alpha.7

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate error-messaging feature: 🏔 data cascade Issues related to the Data Cascade feature
Projects
None yet
Development

No branches or pull requests

5 participants