eleventy
eleventy copied to clipboard
Serverless function has stopped working locally and in production
Describe the bug
Hi, I have a serverless function that renders previews in Sanity.io (great feature!), but at some point over the course of the last month it stopped working. I've previously been able to get it to work (referenced in this previous issue I opened then closed) by moving the functions folder to the root of my mono repo because it seemed like the lambda functions weren't capable of working with a nested functions folder. Now ever since this new issue has popped up, when I run netlify dev locally from the root of the project (like I always did), I get the following error:
Cannot find module '/[root of project]/eleventy-serverless-map.json'
I expect 11ty to be looking in the functions directory specified in my netlify.toml for this particular file but its looking in the root of the project which I believe is the issue. My netlify.toml file looks like the following:
[build]
command = "yarn build"
publish = "web/build" # the nested site directory build folder
[functions]
directory = "netlify/functions" # functions folder, that lives adjacent to this file in the repo
[[redirects]]
from = "/preview/:slug"
to = "/.netlify/functions/preview"
status = 200
force = true
_generated_by_eleventy_serverless = "preview"
[[redirects]]
from = "/preview/"
to = "/.netlify/functions/preview"
status = 200
force = true
_generated_by_eleventy_serverless = "preview"
To Reproduce Steps to reproduce the behavior:
Steps are a bit specific to my project.
1.Create a netlify functions folder at the root of a monorepo with a yarn configuration that builds the actual site to a subdirectory (in my case this is web).
2. Account for this in netlify.toml by pointing build and dev commands to that directory.
3. Run netlify dev from the root of the project.
4. Encounter issue.
Expected behavior 11ty serverless plugin looks in the functions folder for the generated serverless build files instead of in the root of the repository.
Environment:
- OS and Version: MacOS Big Sur 11.6.3
- Eleventy Version: 1.0.1
We don’t automatically parse the functions directory location from your netlify.toml but do provide an option to specify it in the bundler plugin: https://www.11ty.dev/docs/plugins/serverless/#bundler-options
Do those match up?
I seem to be having the same issue where I get the error message
`Cannot find module '/[root of project]/eleventy-serverless-map.json'
Shouldn't it be looking inside the netlify/preview folder?
I can't seem to be able to figure this out, it seems like inputDir is no longer being used?
@zachleat any thoughts?
I just ran into the same issue.
There must be something wrong as the website has been functioning normally for 4 months when suddenly I see the same error:
Error - Cannot find module '/var/task/eleventy-serverless-map.json' Require stack: - /var/task/node_modules/@11ty/eleventy/src/Serverless.js - /var/task/node_modules/@11ty/eleventy/src/Eleventy.js - /var/task/functions/serverless/index.js - /var/task/serverless.js - /var/runtime/index.mjs
Interestingly this only affects production when the site is deployed from the Netlify UI or triggered by a push to the git repo: when I run the site locally using netlify dev the eleventy serverless function works as expected. Also, if I deploy using netlify cli with netlify deploy --prod then production also works as expected. Help!
I am using Eleventy 2.0.1 and Netlify Cli 16.5.1
Okay so thanks to this thread, I found the solution.
Add the following the netlify.toml file:
[functions] node_bundler = "zisi"
Stale per project slipstream changes in #3074.