-
Notifications
You must be signed in to change notification settings - Fork 340
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
Cannot use node-fetch 3 in serverless functions #4558
Comments
Closing because the fix is to name the serverless function with the .mjs extension. |
I've reopened the issue as I think we need some communication around this on the docs, OR, compile .js files that are using the import syntax correctly under the hood. |
Spoke to @whitep4nth3r briefly about this during the DX Mobbing meeting, and I wanted to surface this for @klavavej to see if this is something that needs to be added to the Functions docs, since this is something that seems to be causing a lot of issues. |
this is somewhat related to https://github.com/netlify/docs/issues/1402 |
I believe if you use: [functions]
node_bundler = "esbuild" it will fix the error and you can directly use |
Agreed @hrishikesh-k — I guess I didn't find good docs about this at the time. We have a blog post out now — but just wanted to follow up with @klavavej as to whether this is now clearer on the docs? |
@hrishikesh-k @whitep4nth3r - support for ESM in the default Since folks are now seeing that https://github.com/netlify/pod-compute/issues/147 has been filed to look into the possible regression Related docs issue https://github.com/netlify/docs/issues/1760 |
Describe the bug
Using node-fetch 3 (latest) causes serverless functions to error and not run.
Steps to reproduce
import fetch from "node-fetch"
Note: Using node-fetch 2 and importing the dependency via
const fetch = require("node-fetch");
works as expected.Configuration
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
Environment
System:
OS: macOS 12.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 2.33 GB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 17.9.0 - /opt/homebrew/bin/node
Yarn: 1.22.18 - /opt/homebrew/bin/yarn
npm: 8.5.5 - /opt/homebrew/bin/npm
npmGlobalPackages:
netlify-cli: 10.0.0
The text was updated successfully, but these errors were encountered: