Open whitep4nth3r opened 2 years ago
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.
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'd like to see what engineering thinks about fixing this bug before trying to address this pain point with a docs update
I believe if you use:
[functions]
node_bundler = "esbuild"
it will fix the error and you can directly use .js
files. To me, this doesn't appear to be a bug, as we need folks to use esbuild
to import ESM modules.
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 zisi
bundler was added in https://github.com/netlify/zip-it-and-ship-it/pull/1018
Since folks are now seeing that node_bundler = "esbuild"
is required for .js
functions using ESM, I suspect there's been a regression with the feature enhancement to support ESM regardless of the bundler.
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