11ty / eleventy

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

TemplateLayoutPathResolver error #489

Closed alienlebarge closed 5 years ago

alienlebarge commented 5 years ago

Hi !

I have a problem which I can't figure out how to solve. Perhaps someone can help me here šŸ¤ž

Description

When running a $ npm run dubug (or $ DEBUG=* npx eleventy), I get the following error:

Eleventy:EleventyErrorHandler Problem writing Eleventy templates: +0ms
  Eleventy:EleventyErrorHandler TemplateLayoutPathResolver directory does not exist for layouts/bookmark.njk: _includes (Error): +1ms
  Eleventy:EleventyErrorHandler (error stack): Error: TemplateLayoutPathResolver directory does not exist for layouts/bookmark.njk: _includes
  Eleventy:EleventyErrorHandler     at TemplateLayoutPathResolver.findFileName (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:96:13)
  Eleventy:EleventyErrorHandler     at TemplateLayoutPathResolver.init (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:61:28)
  Eleventy:EleventyErrorHandler     at new TemplateLayoutPathResolver (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:15:10)
  Eleventy:EleventyErrorHandler     at new TemplateLayout (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/TemplateLayout.js:15:24)
  Eleventy:EleventyErrorHandler     at Function.getTemplate (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/TemplateLayout.js:38:16)
  Eleventy:EleventyErrorHandler     at Template.getData (/Users/cedricaellen/Projects/alienlebargech-v3/node_modules/@11ty/eleventy/src/Template.js:217:37) +0ms
Processed 0 files in 2.54 seconds

but when running an standard build $ eleventy --config lib/eleventy.config.js, I get no error. This means I can build locally my website but not when pushing on Netlify

Ask

I can't find where the problem come from.

Things I've tried

Change value of layout in src/_content/bookmarks/bookmarks.json It change the second line of the error message but can't make it work

Additional Info

zachleat commented 5 years ago

Hey @alienlebarge I think your npm run debug needs your config file to be passed in. Use https://www.11ty.io/docs/usage/#--config-to-change-the-config-file-name to do this.

https://github.com/alienlebarge/alienlebargech-v3/blob/master/package.json#L16

should be "debug": "DEBUG=* npx eleventy --config=lib/eleventy.config.js"

Note that --config=lib/eleventy.config.js uses an equal sign (looks like that might be wrong in a few places in your package.json

alienlebarge commented 5 years ago

@zachleat, thanks for help.

The debug script is fixed. But I still have problems to deploy on Netlify. I have no error when serving the website locally but it doesn't work on Netlify. Here's the error I get on Netlify:

3:10:35 PM: > eleventy --config=lib/eleventy.config.js
3:10:40 PM: Problem writing Eleventy templates: (more in DEBUG output)
3:10:40 PM: > Having trouble rendering njk template ./src/_content/indices/bookmarks.njk (TemplateContentRenderError)
3:10:40 PM: > (unknown path)
3:10:40 PM:   Template render error: (/opt/build/repo/src/_includes/item/bookmark.njk)
3:10:40 PM:   ReferenceError: URL is not defined (Template render error):
3:10:40 PM:     Template render error: (unknown path)
3:10:40 PM:       Template render error: (/opt/build/repo/src/_includes/item/bookmark.njk)
3:10:40 PM:       ReferenceError: URL is not defined
3:10:40 PM:         at Object._prettifyError (/opt/build/repo/node_modules/nunjucks/src/lib.js:36:11)
3:10:40 PM:         at /opt/build/repo/node_modules/nunjucks/src/environment.js:567:19
3:10:40 PM:         at eval (eval at _compile (/opt/build/repo/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:11:11)
3:10:40 PM:         at /opt/build/repo/node_modules/nunjucks/src/environment.js:617:9
3:10:40 PM:         at eval (eval at _compile (/opt/build/repo/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:42:12)
3:10:40 PM:         at /opt/build/repo/node_modules/nunjucks/src/environment.js:575:11
3:10:40 PM:         at Template.root [as rootRenderFunc] (eval at _compile (/opt/build/repo/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:41:3)
3:10:40 PM:         at Template.render (/opt/build/repo/node_modules/nunjucks/src/environment.js:556:10)
3:10:40 PM:         at eval (eval at _compile (/opt/build/repo/node_modules/nunjucks/src/environment.js:637:18), <anonymous>:41:10)
3:10:40 PM:         at fn (/opt/build/repo/node_modules/a-sync-waterfall/index.js:26:24)
3:10:40 PM: Copied 2 items and Processed 0 files in 4.44 seconds
3:10:40 PM: npm

Here is a PR I made to test that: alienlebarge/alienlebargech-v3#5

I found that the problem come from this script: https://github.com/alienlebarge/alienlebargech-v3/blob/fix-config/lib/filters/hostname.js#L8-L12 If I comment it, the deployment work. Screen Capture on 2019-04-14 at 23-29-20

alienlebarge commented 5 years ago

Node version wasn't the same locally than on production. Adding .nvmrc file with the Node version fixed the problem

Thanks for your help @zachleat šŸ‘Œ