@@ -342,6 +342,20 @@ export default defineNuxtConfig({
342342
343343 nitro : {
344344 preset : 'netlify' ,
345+ // sanitize-html is CommonJS but depends on htmlparser2 ^12, which is ESM-only
346+ // ("type": "module", main ./dist/index.js). Left external, Nitro require()s it from
347+ // /var/task/node_modules in the deployed function, and require() of an ES module only
348+ // works on Node >= 22.12 - which is why sanitize-html declares engines node >=22.12.0.
349+ // The Lambda runtime under this site is older than that, so the require threw
350+ // ERR_REQUIRE_ESM at module load. server/utils is auto-imported by Nitro, so that one
351+ // throw took down every route the fallback function serves: robots.txt, /api/*, and
352+ // every 404, all returning 502. Inlining it makes rollup resolve htmlparser2 at build
353+ // time, so the function no longer require()s ESM and this holds on any runtime.
354+ // The runtime version itself is a Netlify site setting (AWS_LAMBDA_JS_RUNTIME); it
355+ // cannot be set from netlify.toml, so it is not fixable here.
356+ externals : {
357+ inline : [ 'sanitize-html' ]
358+ } ,
345359 // Nitro emits a .mjs.map next to every server chunk, so the Netlify functions bundle
346360 // ships one map file per chunk. Skipping them keeps the bundle smaller and the
347361 // server build a little shorter. The cost is that a server-side stack trace in the
@@ -395,6 +409,13 @@ export default defineNuxtConfig({
395409 // content-urls.get.ts) silently resolves to undefined. Explicitly listing
396410 // it here bakes it at build time instead, inside the git checkout.
397411 '/sitemap.xml' ,
412+ // Same hybrid-preset gate as /sitemap.xml above: @nuxtjs/robots only
413+ // writes robots.txt to nuxt/dist when isNuxtGenerate() is true, so on the
414+ // netlify preset it was served live by the fallback function instead. Any
415+ // fault in that function therefore turned robots.txt into a 5xx, and
416+ // Google reads a 5xx on robots.txt as "crawl nothing" for the first ~12h.
417+ // Listing it here makes it a static file, independent of the function.
418+ '/robots.txt' ,
398419 '/contact-us' ,
399420 '/book-demo' ,
400421 '/support' ,
0 commit comments