3

I have a aws lambda function which calls the eleventy.write() or eleventy.toJSON() method but can't seem to make it work. I have tried different project structures and setting different paths but it either returns an empty array or it throws the following error TemplateLayoutPathResolver directory does not exist for filename.njk: _includes When I run the eleventy command from terminal, it builds successfully. This is my 11ty project structure

project root folder
-- public (output of the eleventy build)
-- .eleventy.js
-- src (input for the eleventy build)
  |-- _data
  |-- _includes

my .eleventy.js file looks like this:

...
 return {
        dir:{
            input: 'src',
            output: 'public',
        },
    };

On the lambda function project, where the write() call is made, I have tried setting the input path relative to the file, then I tried putting the 11ty root folder next to the .js file and instantiating eleventy like let eleventy = new Eleventy(".", "public") which didn't worked and I also tried taking the content of the eleventy root project and placing it next to the .js file I am making the write() call.

Also tried setting the configPath like so

let eleventy = new Eleventy(".", "public", {
    configPath: "./.eleventy.js",
  });

but still not working.

The documentation for the eleventy programmatic API (https://www.11ty.dev/docs/programmatic/) is pretty thin, so any help will be greatly appreciated.

2 Answers2

1

Looking at your list of files above, in src, I see includes, not _includes. Did you forget the underscore?

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • Forgot to write in in the post, my bad. I updated the post – Cristian Beckert May 18 '22 at 21:59
  • And I assume you have files in src? After you fixed the _ issue, what do you get currently? You maybe need to edit the question to reflect the current status/result. – Raymond Camden May 19 '22 at 22:04
  • Yes I do have files in src, and I also had the underscore in _includes initially, it was just a typo in the post, but like I already mentioned, if I build the app using the "eleventy" command, it works just fine. The problem is with the programmatic api – Cristian Beckert May 20 '22 at 22:58
0

Just set your input folder to "src"

let eleventy = new Eleventy("src", "public");
tay
  • 138
  • 2
  • 13