nuxt-modules / sitemap

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
https://nuxtseo.com/sitemap
MIT License
336 stars 31 forks source link

Cloudflare Pages fix??? #380

Closed DavidFrings closed 2 weeks ago

DavidFrings commented 3 weeks ago

Description:

I encountered the same issue as described in #259. After some investigation, I believe I have identified the cause.

While reviewing the dependencies unenv, h3, h3-compression, and sitemap, I found the following note in the README of the h3-compression package:

[!NOTE]
useCompressionStream doesn't work right now in Nitro. You should use useCompression instead.

Source

The relevant code in the sitemap module appears to be calling useCompressionStream:

import { useCompressionStream } from 'h3-compression'
import { defineNitroPlugin } from '#imports'

export default defineNitroPlugin((nitro) => {
  nitro.hooks.hook('beforeResponse', async (event, response) => {
    if (event.context._isSitemap)
      await useCompressionStream(event, response)    <-------------------------
  })
})

Source

Conclusion:

It seems like there's a mismatch between the method being used (useCompressionStream) and the functionality currently supported in h3-compression (which only supports useCompression). Replacing useCompressionStream with useCompression should resolve the issue.

I would really appreciate it if this could be fixed, but I'm not making the change myself as I'm not familiar with this module.

Let me know if you need further clarification.

DavidFrings commented 3 weeks ago

🙏

harlan-zw commented 2 weeks ago

Hi, thanks for the issue and PR.

I've taken a look and I'm not sure if this is exactly right. Are you able to provide the error you're getting? If it's the exact same as the linked issue then I don't think this is the right diagnosis.

Keep in mind that compression is only used when experimentalCompression is manually enabled.

Btw streaming is supported in Nitro: https://github.com/nitrojs/nitro/issues/1327, I think the docs are outdated.

DavidFrings commented 2 weeks ago

Here is a shortet version of my logs:

Detected the following tools from environment: nodejs@20.12.2, pnpm@9.12.2
dependencies:
    + hammerjs 2.0.8
    + nuxt 3.13.2
    + prettier 3.3.3
    + vue 3.5.11
    + vue-router 4.4.5

devDependencies:
    + @emotion/css 11.13.4
    + @nuxtjs/i18n 9.0.0-rc.2
    + @nuxtjs/sitemap 6.1.2
    + @vite-pwa/nuxt 0.10.5
    + nuxt-security 2.0.0

Executing user command: pnpm install && pnpm run format && pnpm run build --if-present

> nuxt build "--if-present"
[log] Nuxt 3.13.2 with Nitro 2.9.7
[success] Client built in 2496ms
[info] Building server...
[info] ite v5.4.8] building SSR bundle for production...
[plugin] [unplugin-vue-i18n:directive] Sourcemap is likely to be incorrect: a plugin (unplugin-vue-i18n:directive) was used to transform files, but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help
[success] Server built in 1705ms
[success] [nitro] Generated public dist

PWA v0.20.5
mode      generateSW
precache  3 entries (0.41 KiB)
files generated
 dist/sw.js
 dist/workbox-cbf83eee.js

[info] [nitro] Building Nuxt Nitro server (preset: `cloudflare_pages`)
[error] [nitro] RollupError: .nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js (1:9): "stdin" is not exported by "node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/node/process/index.mjs", imported by ".nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js".

1: import { stdin, stdout } from "node:process";
                ^
2: import f from "node:readline";
3: import { WriteStream } from "node:tty";

[error] .nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js (1:9): "stdin" is not exported by "node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/node/process/index.mjs", imported by ".nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js".
      at getRollupError (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/parseAst.js:395:41)
      at error (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/parseAst.js:391:42)
      at Module.error (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:15535:16)
      at Module.traceVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:15984:29)
      at ModuleScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:13770:39)
      at ChildScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5252:38)
      at ClassBodyScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5252:38)
      at ChildScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5252:38)
      at ChildScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5252:38)
      at FunctionScope.findVariable (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5252:38)
      at Identifier.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:5035:40)
      at AssignmentPattern.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2855:23)
      at Property.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2855:23)
      at ObjectPattern.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2851:28)
      at FunctionExpression.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2851:28)
      at MethodDefinition.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2855:23)
      at ClassBody.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2851:28)
      at ClassDeclaration.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2855:23)
      at Program.bind (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:2851:28)
      at Module.bindReferences (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:15514:18)
      at Graph.sortModules (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:21019:20)
      at Graph.build (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:20922:14)
      at async node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:21607:13
      at async catchUnfinishedHookActions (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:21076:16)
      at async rollupInternal (node_modules/.pnpm/rollup@4.24.0/node_modules/rollup/dist/es/shared/node-entry.js:21602:5)
      at async _build (node_modules/.pnpm/nitropack@2.9.7_magicast@0.3.5/node_modules/nitropack/dist/nitro.mjs:2633:20)
      at async node_modules/.pnpm/nuxt@3.13.2_@parcel+watcher@2.4.1_@types+node@22.7.4_eslint@9.13.0_jiti@2.3.1__ioredis@5.4.1__5dzmqmjnledb6iljrfoadnkny4/node_modules/nuxt/dist/index.mjs:3630:5
      at async build (node_modules/.pnpm/nuxt@3.13.2_@parcel+watcher@2.4.1_@types+node@22.7.4_eslint@9.13.0_jiti@2.3.1__ioredis@5.4.1__5dzmqmjnledb6iljrfoadnkny4/node_modules/nuxt/dist/index.mjs:5778:3)
      at async Object.run (node_modules/.pnpm/nuxi@3.14.0/node_modules/nuxi/dist/chunks/build.mjs:101:5)
      at async runCommand$1 (node_modules/.pnpm/nuxi@3.14.0/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1648:16)
      at async runCommand$1 (node_modules/.pnpm/nuxi@3.14.0/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1639:11)
      at async runMain$1 (node_modules/.pnpm/nuxi@3.14.0/node_modules/nuxi/dist/shared/nuxi.3e201632.mjs:1777:7) 

[error] .nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js (1:9): "stdin" is not exported by "node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/node/process/index.mjs", imported by ".nuxt/dist/server/_nuxt/prompt-BGYTzdFy.js".
Command failed with exit code 1.
harlan-zw commented 2 weeks ago

Thanks, I'd recommend you upgrade your Nuxt and Nitro versions as I'm pretty sure this is an upstream bug.

You can do nuxi upgrade --force

DavidFrings commented 2 weeks ago

didn't worked for me... Note: the error only exists in the build script...

harlan-zw commented 2 weeks ago

I'd recommend enabling hoisting pnpm i --shamefully-hoist

You need to add shamefully-hoist=true to the .npmrc file. Although, I do not understand what exactly it does

The issue relates to mismatched dependencies in Nuxt

DavidFrings commented 2 weeks ago

Yes, it worked for me!

Thank you for your nice support