11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.

Home Page:https://www.11ty.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

serverlessFilePath is not defined (2.0.0-beta.2)

mrmartineau opened this issue · comments

Operating system

macOS Ventura 13.1

Eleventy

2.0.0-beta.2

Describe the bug

While trying to debug an issue with my serverless function (/search) on Netlify, I thought I would try the latest beta (2.0.0-beta.2). I was on the previous beta (2.0.0-beta.1).

When running my project locally, the initial build is fine, but when I visit a page, this error is printed in the terminal console:

[0] [11ty] Unhandled rejection in promise: (more in DEBUG output)
[0] [11ty] serverlessFilePath is not defined (via ReferenceError)
[0] [11ty]
[0] [11ty] Original error stack trace: ReferenceError: serverlessFilePath is not defined
[0] [11ty]     at BundlerHelper.EleventyServerlessMiddleware (/Users/zander/code/mrmartineau/11ty-notes/node_modules/@11ty/eleventy/src/Plugins/ServerlessBundlerPlugin.js:171:26)
[0] [11ty]     at EleventyDevServer.eleventyDevServerMiddleware (/Users/zander/code/mrmartineau/11ty-notes/node_modules/@11ty/eleventy-dev-server/server.js:405:5)
[0] [11ty]     at EleventyDevServer.onRequestHandler (/Users/zander/code/mrmartineau/11ty-notes/node_modules/@11ty/eleventy-dev-server/server.js:516:11)
[0] [11ty]     at Server.emit (node:events:513:28)
[0] [11ty]     at parserOnIncoming (node:_http_server:980:12)
[0] [11ty]     at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)

The only mention of serverlessFilePath in the 11ty codebase is from here which makes use of a couple of TemplatePath utils. Perhaps one of them is at fault..

let serverlessFilepath = TemplatePath.addLeadingDotSlash(
  path.join(TemplatePath.getWorkingDir(), this.dir, "index")
);

If I comment-out these lines in my 11ty config, the site loads and there are no issues..

eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
  name: 'search',
  functionsDir: './netlify/functions/',
})

On another note, when deployed to Netlify the serverless function times out and does not work at all despite being absolutely fine locally when using 2.0.0-beta.1. I have no idea why that could be. Does the serverless setup in my repo look correct?

The function logs show this when they are used:

Jan 29, 07:57:19 PM: 2376f0de 2023-01-29T19:57:30.939Z 2376f0de-fdf1-467b-a50c-62958f901b64 Task timed out after 10.01 seconds
Jan 29, 07:57:29 PM: 2376f0de Duration: 10013.75 ms	Memory Usage: 104 MB	Init Duration: 835.66 ms

Does this look ok for Netlify's free tier? I don't think it's hitting any limits.

I know I've mentioned 2 issues here, but I'm not sure if they're related or not.

Reproduction steps

  1. Create a .env file in the root with this content:
ALGOLIA_APP = "1234"
ALGOLIA_SEARCH_KEY = "1234"
ALGOLIA_INDEX = "notes"
  1. Run the dev script: npm run dev
  2. Browse to a page, it will not show anything but the terminal will show the error detailed above.

Expected behavior

The site should work.

Reproduction URL

https://github.com/mrmartineau/11ty-notes

Screenshots

No response

After a little digging, I have found the specific issue, it's actually an incorrectly named variable. It is not related to the below snippet like I thought it was

let serverlessFilepath = TemplatePath.addLeadingDotSlash(
  path.join(TemplatePath.getWorkingDir(), this.dir, "index")
);

but rather the intended usage of it further on, on line 171, albeit with an incorrect variable name serverlessFilePath when it should be serverlessFilepath.

deleteRequireCache(serverlessFilepath); // this is what it should be

I changed the variable locally and everything works as expected now. I am in the process of creating PR for the fix too which should be ready soon.

Thank you! This will ship with 2.0.0-canary.35 and 2.0.0-beta.3

Fixed by #2783