Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless function has stopped working locally and in production #2414

Closed
qonl opened this issue May 30, 2022 · 5 comments
Closed

Serverless function has stopped working locally and in production #2414

qonl opened this issue May 30, 2022 · 5 comments
Labels
feature: 🏙 serverless Eleventy Serverless needs-triage open-question Requires additional information before we can proceed.

Comments

@qonl
Copy link

qonl commented May 30, 2022

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
@zachleat zachleat added the feature: 🏙 serverless Eleventy Serverless label Jun 16, 2022
@zachleat
Copy link
Member

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?

@zachleat zachleat added the open-question Requires additional information before we can proceed. label Jun 16, 2022
@ArmandoAmador
Copy link

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?

@treb0r
Copy link

treb0r commented Oct 5, 2023

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

@treb0r
Copy link

treb0r commented Oct 5, 2023

Okay so thanks to this thread, I found the solution.

Add the following the netlify.toml file:
[functions] node_bundler = "zisi"

@zachleat
Copy link
Member

zachleat commented Apr 9, 2024

Stale per project slipstream changes in #3074.

@zachleat zachleat closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: 🏙 serverless Eleventy Serverless needs-triage open-question Requires additional information before we can proceed.
Projects
None yet
Development

No branches or pull requests

4 participants