11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.1k stars 494 forks source link

TemplateLayoutPathResolver directory does not exist for default: _includes #1642

Closed 3goats closed 3 years ago

3goats commented 3 years ago

Hi,

Im using the skeleventy starter project and have noticed that the Eleventy config file is called eleventy.config.js as oppose .eleventy.js as per the docs. When I run 'npm run dev' my site compiles and runs fine. However, If I rename my eleventy.config.js to .eleventy.js or use the eleventy command to build, I get the following error:

npx eleventy 
Problem writing Eleventy templates: (more in DEBUG output)
> TemplateLayoutPathResolver directory does not exist for default: _includes

`Error` was thrown:
    Error: TemplateLayoutPathResolver directory does not exist for default: _includes
        at TemplateLayoutPathResolver.findFileName (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:96:13)
        at TemplateLayoutPathResolver.init (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:61:28)
        at new TemplateLayoutPathResolver (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:15:10)
        at new TemplateLayout (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateLayout.js:15:24)
        at Function.getTemplate (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateLayout.js:38:16)
        at Template.getData (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/Template.js:219:37)
        at async Template.getTemplateMapEntries (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/Template.js:681:16)
        at async TemplateMap.add (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateMap.js:32:21)
        at async Promise.all (index 5)
        at async TemplateWriter._createTemplateMap (/Users/cbourne/development/11ty-hype/node_modules/@11ty/eleventy/src/TemplateWriter.js:132:5)
Wrote 0 files in 0.17 seconds (v0.10.0)

My eleventy.config.js looks like this:

const htmlmin = require("html-minifier")

module.exports = eleventyConfig => {

    // Add a readable date formatter filter to Nunjucks
    eleventyConfig.addFilter("dateDisplay", require("./filters/dates.js"))

    // Add a HTML timestamp formatter filter to Nunjucks
    eleventyConfig.addFilter("htmlDateDisplay", require("./filters/timestamp.js"))

    // Minify our HTML
    eleventyConfig.addTransform("htmlmin", (content, outputPath) => {
        if ( outputPath.endsWith(".html") )
        {
            let minified = htmlmin.minify(content, {
                useShortDoctype: true,
                removeComments: true,
                collapseWhitespace: true
            })
            return minified
        }
        return content
    })

    // Collections
    eleventyConfig.addCollection('blog', collection => {

        const blogs = collection.getFilteredByTag('blog')

        for( let i = 0; i < blogs.length; i++ ) {

            const prevPost = blogs[i - 1]
            const nextPost = blogs[i + 1]

            blogs[i].data["prevPost"] = prevPost
            blogs[i].data["nextPost"] = nextPost

        }

        return blogs.reverse()

    })

    // Layout aliases
    eleventyConfig.addLayoutAlias('default', 'layouts/default.njk')
    eleventyConfig.addLayoutAlias('post', 'layouts/post.njk')

    // Include our static assets
    eleventyConfig.addPassthroughCopy("css")
    eleventyConfig.addPassthroughCopy("js")
    eleventyConfig.addPassthroughCopy("images")
    eleventyConfig.addPassthroughCopy("animations")
    eleventyConfig.addPassthroughCopy("robots.txt")

    return {
        templateFormats: ["md", "njk"],
        markdownTemplateEngine: 'njk',
        htmlTemplateEngine: 'njk',
        passthroughFileCopy: true,

        dir: {
            input: 'site',
            output: 'dist',
            includes: 'includes',
            data: 'globals'
        }
    }     
}

And my directory structure looks like this:


├── README.md
├── _site
│   ├── css
│   │   ├── main.css
│   │   └── main.min.css
│   └── images
│       ├── blog
│       │   ├── author.jpg
│       │   ├── post-1.jpg
│       │   ├── post-2.jpg
│       │   └── post-3.jpg
│       ├── favicon.ico
│       ├── icons
│       │   └── icon-library.svg
│       ├── logo
│       │   └── logo.svg
│       └── meta
│           ├── og.jpg
│           └── twitter.jpg
├── css
│   ├── main.css
│   └── main.min.css
├── eleventy.config.js
├── filters
│   ├── dates.js
│   └── timestamp.js
├── images
│   ├── blog
│   │   ├── author.jpg
│   │   ├── post-1.jpg
│   │   ├── post-2.jpg
│   │   └── post-3.jpg
│   ├── favicon.ico
│   ├── icons
│   │   └── icon-library.svg
│   ├── logo
│   │   └── logo.svg
│   └── meta
│       ├── og.jpg
│       └── twitter.jpg
├── mix-manifest.json
├── package-lock.json
├── package.json
├── site
│   ├── 404.njk
│   ├── about.njk
│   ├── blog
│   │   ├── blog-4.md
│   │   ├── blog.json
│   │   ├── post-1.md
│   │   ├── post-2.md
│   │   └── post-3.md
│   ├── blog.njk
│   ├── contact.njk
│   ├── globals
│   │   ├── helpers.js
│   │   ├── navigation.json
│   │   └── site.json
│   ├── includes
│   │   ├── components
│   │   │   ├── footer.njk
│   │   │   ├── header.njk
│   │   │   ├── logo.njk
│   │   │   ├── mobile-nav.njk
│   │   │   ├── nav.njk
│   │   │   ├── social-icons.njk
│   │   │   └── social-meta.njk
│   │   └── layouts
│   │       ├── default.njk
│   │       └── post.njk
│   ├── index.njk
│   ├── robots.njk
│   ├── sitemap.njk
│   └── tags.njk
├── src
│   └── animation_script_inc.njk
├── tailwind.config.js
├── webpack.mix.js
└── www
    └── animation_script_inc
        └── index.html

Any guidance would be much appreciated.

3goats commented 3 years ago

OK, so doing this eleventy --config=./eleventy.config.js seems to resolve the issue. However, it seems renaming the config file to .eleventy.js means it still doesn't get found by default.

zachleat commented 3 years ago

I believe this error happens when you use the non-default includes folder (e.g. includes in your case) and you aren’t pointing to the --config file. So we look for the default _includes which doesn’t exist?

This is about Eleventy not knowing where your config file is, right?

zachleat commented 3 years ago

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and I will reopen the issue. Thanks!

Hestre-M commented 9 months ago

hi i am having this issue when i use eleventy within a workspace of a mono repo