harlan-zw / nuxt-seo

The complete SEO solution for Nuxt.
https://nuxtseo.com
MIT License
1.08k stars 70 forks source link

with @nuxtjs/seo when deploying to Cloudflare ("stdin" is not exported) #218

Closed acdxxx177 closed 4 months ago

acdxxx177 commented 7 months ago

Describe the bug

I am currently using the @nuxtjs/seo module in my Nuxt 3 project for SEO optimization. However, I encountered an issue when deploying my application to Cloudflare.

The error message is as follows:

✔ Server built in 3171ms 16:55:56 ℹ Initializing prerenderer nitro 16:55:57 ℹ Prerendering 1 routes nitro 16:56:07 ├─ /api/_content/cache.1712220946370.json (76ms) nitro 16:56:07 ℹ Prerendered 1 routes in 10.104 seconds nitro 16:56:07 ✔ Generated public dist nitro 16:56:07 ℹ Building Nuxt Nitro server (preset: cloudflare-pages) nitro 16:56:07

[nitro 16:56:16] ERROR RollupError: "stdin" is not exported by "node_modules/.pnpm/unenv@1.9.0/node_modules/unenv/runtime/node/process/index.mjs", imported by ".nuxt/dist/server/_nuxt/prompt-W7GJNXZP.js".

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

[16:56:16] ERROR "stdin" is not exported by "node_modules/.pnpm/unenv@1.9.0/node_modules/unenv/runtime/node/process/index.mjs", imported by ".nuxt/dist/server/_nuxt/prompt-W7GJNXZP.js".

This error occurs when I set the NITRO_PRESET environment variable to cloudflare-pages and run nuxt build.

Here is the relevant part of my nuxt.config.ts:

export default defineNuxtConfig({
  modules: ["@nuxtjs/seo", "@nuxtjs/i18n", "@nuxt/content"],
  i18n: {
    vueI18n: "./i18n.config.ts",
    locales: [
      { code: "en", iso: "en-US" },
    ],
    defaultLocale: "en",
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: "i18n_redirected",
      redirectOn: "root",
    },
  },
  site: {
    url: "http://www.xxxxx.xxx",
    name: "xxxxxxxxxxx",
    description: "xxxxxxxxxx",
  },
  content: {},
  devtools: { enabled: true },
  nitro: {
    preset: 'cloudflare-pages',
    prerender: {
      autoSubfolderIndex: false
    }
  },
});

I encounter this error both on the Cloudflare website and locally. If I remove '@nuxtjs/seo' or the 'preset: cloudflare-pages' configuration, the build proceeds without any issues.

Reproduction

No response

System / Nuxt Info

------------------------------
- Operating System: Windows_NT
- Node Version:     v20.11.1
- Nuxt Version:     3.10.3
- CLI Version:      3.10.1
- Nitro Version:    2.9.3
- Package Manager:  pnpm@8.15.5
- Builder:          -
- User Config:      modules, i18n, site, content, devtools, nitro
- Runtime Modules:  @nuxtjs/seo@2.0.0-rc.8, @nuxtjs/i18n@8.1.1, @nuxt/content@2.12.1
- Build Modules:    -
------------------------------
acdxxx177 commented 7 months ago

I have tested the modules one by one and found that as long as there are "@nuxtjs/seo", "@nuxtjs/i18n", and "preset: 'cloudflare-pages'" configurations, this issue will definitely occur. Below is my minimal configuration:

// nuxt.config.ts
export default defineNuxtConfig({
  devtools: { enabled: true },
  modules: ["@nuxtjs/seo", "@nuxtjs/i18n"],
  nitro: {
    preset: "cloudflare-pages",
    prerender: {
      autoSubfolderIndex: false,
    },
  },
  ogImage: {
    enabled: false,
  },
  sitemap: {
    enabled: false,
  },
  robots: {
    enabled: false,
  },
  seoExperiments: {
    enabled: false,
  },
  schemaOrg: {
    enabled: false,
  },
  linkChecker: {
    enabled: false,
  },
});
harlan-zw commented 4 months ago

This seems like an upstream Nitro bug, could you confirm if it's still an issue using latest versions of everything? Will close for now but happy to re-open if you can confirm.

raggesilver commented 2 months ago

@acdxxx177, setting shamefully-hoist=true on .npmrc and reinstalling everything with pnpm worked for me.

acdxxx177 commented 2 months ago

@acdxxx177, setting shamefully-hoist=true on .npmrc and reinstalling everything with pnpm worked for me. Thanks, it worked for me, I also tried npm, it worked too