I’m having issues after deploying my Astro site. I’m using the official Netlify adapter for Astro for SSR.
The site works during development but the errors suggest it has something to do with ES modules / Common JS modules.
Site name: https://es-sale.netlify.app/
Site ID: a556a44d-4591-4c01-baa0-ba1de15468da
Having the same issues as this post: [Bug]: ESM not supported with Netlify functions? (part 2) · Issue #1456 · netlify/next-runtime · GitHub
They are configuring their NODE_VERSION and AWS_LAMBDA_JS_RUNTIME in their netlify.toml build environment but mentioned that it didn’t work. I’m using node 16.13.0.
An unhandled error in the function code triggered the following message:
Error - require() of ES Module /var/task/node_modules/astro/dist/core/app/index.js from /var/task/.netlify/functions-internal/entry.js not supported. Instead change the require of index.js in /var/task/.netlify/functions-internal/entry.js to a dynamic import() which is available in all CommonJS modules.
Stack Trace:
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/task/node_modules/astro/dist/core/app/index.js from /var/task/.netlify/functions-internal/entry.js not supported.
Instead change the require of index.js in /var/task/.netlify/functions-internal/entry.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/var/task/.netlify/functions-internal/entry.js:43036:18)
at Object.<anonymous> (/var/task/entry.js:1:18)
at _tryRequireFile (file:///var/runtime/index.mjs:912:37)
at _tryRequire (file:///var/runtime/index.mjs:962:25)
at _loadUserApp (file:///var/runtime/index.mjs:991:22)
at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1029:27)
at start (file:///var/runtime/index.mjs:1192:42)
at file:///var/runtime/index.mjs:1198:7
- I’m using “type”: “module” in package.json
- I’ve tried searching through the node_modules/astro/dist/core/app/index.js file but did not find any require() statements and am unable to access .netlify/functions-internal/entry.js as it doesn’t exist in my project folders.
- Tried adding node_bundler = “esbuild” to the netlify.toml file which currently looks like this:
[build]
command = "npm run build"
publish = "dist"
[functions]
external_node_modules = ["astro"]
node_bundler = "esbuild"
Could someone from netlify please help me with this?