framework icon indicating copy to clipboard operation
framework copied to clipboard

static asset 404s print `[nitro] Error while generating error response FetchError: 404`

Open nooperpudd opened this issue 3 years ago • 22 comments

Environment

Nuxt CLI v3.0.0-rc.3 11:53:48 RootDir: /Users/sheilar.gonzalez/vitesse-nuxt3 11:53:51 Nuxt project info: 11:53:51


Nuxt project info: 12:49:50


Reproduction

package.json

{
  "private": true,
  "scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "preview": "nuxi preview",
    "generate": "npx nuxt generate",
    "lint": "vue-cli-service lint",
    "check": "nuxi typecheck client/",
    "start": "node .output/server/index.mjs"
  },
  "dependencies": {
    "@nuxtjs/auth-next": "latest",
    "@nuxtjs/axios": "~5.13.6",
    "@nuxtjs/sanity": "^1.1.1",
    "@nuxtjs/sentry": "^6.0.0-beta.3",
    "@pinia/nuxt": "^0.1.8",
    "bootstrap": "^5.1.3",
    "core-js": "^3.21.1",
    "moment-timezone": "^0.5.34",
    "pinia": "^2.0.11",
    "qs": "^6.10.3",
    "typed.js": "^2.0.12",
    "vue-disqus": "^5.1.0",
    "vue-gtag": "^2.0.1",
    "vue-router": "^4.0.3"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.12.1",
    "@typescript-eslint/parser": "^5.12.1",
    "@vue/cli-plugin-babel": "~5.0.1",
    "@vue/cli-plugin-eslint": "~5.0.1",
    "@vue/cli-plugin-router": "~5.0.1",
    "@vue/cli-service": "~5.0.1",
    "@vue/eslint-config-typescript": "^10.0.0",
    "@vueuse/nuxt": "^8.1.1",
    "autoprefixer": "^10.4.2",
    "eslint": "^8.9.0",
    "eslint-config-prettier": "^8.4.0",
    "eslint-plugin-nuxt": "~3.2.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-vue": "^8.5.0",
    "nuxt": "3.0.0-rc.1",
    "postcss": "^8.4.6",
    "prettier": "^2.4.1",
    "sass": "^1.49.8",
    "sass-loader": "^12.6.0",
    "typescript": "~4.6.2",
    "vue-tsc": "~0.34.3"
  }
}

nuxt config


import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
    meta: {

        link: [
            {
                rel: "stylesheet",
                href: "https://cdn.bootcdn.net/ajax/libs/font-awesome/6.1.0/css/all.min.css"
            },
            {
                rel: "stylesheet",
                href: "https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css"
            },
            {
                rel: "stylesheet",
                href: "https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.8.1/font/bootstrap-icons.min.css"
            }
        ],
        script: [
            // {
            //     type: 'text/javascript',
            //     src: "https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"
            // }
        ]
    },
    srcDir: "client/",
    modules: [
        // "@nuxtjs/axios",
        // "@nuxtjs/auth-next"
        "@nuxtjs/sentry",
        // "@nuxtjs/sanity'"
    ],
    buildModules: [
        "@pinia/nuxt",
        '@vueuse/nuxt',
    ],
    css: ["@/assets/css/base.scss"],
    publicRuntimeConfig: {
        DISQUS_SHORTNAME: "",
        GOOGLE_ANALYSIS: process.env.GOOGLE_ANALYSIS
    },
    env: {
        HOST_URL: process.env.HOST_URL || 'http://127.0.0.1:5000',
    },
    build: {
        postcss: {
            postcssOptions: {
                plugins: {
                    autoprefixer: {},
                }
            }
        }
    },
    // axios: {
    // baseURL: process.env.API_URL || "http://localhost:8000/api"
    // },
    //
    // auth: {
    //
    // },
    // vueuse: {
    //     ssrHandlers: true,
    // },
    // sanity: {
    //     projectId: 'myProject'
    // },
    sentry: {
        dsn: ''
    },
    vite: {
        logLevel: "info"
    }
})

run npm build.


> build
> nuxi build

Nuxt CLI v3.0.0-rc.3                                                                                                                10:45:55
✔ Sentry reporting is enabled (client side: enabled, server side: enabled)                                              nuxt:sentry 10:45:59
vite v2.9.9 building for production...                                                                                              10:46:02
10:46:02 AM [vite] ✨ new dependencies optimized: ufo, pinia/dist/pinia.mjs, vue-disqus, vue-gtag                                   10:46:02
10:46:02 AM [vite] ✨ optimized dependencies changed. reloading                                                                     10:46:02
transforming (25) app.vueℹ Vite client warmed up in 1870ms                                                                                                   10:46:02
✓ 164 modules transformed.                                                                                                          10:46:04
../.nuxt/dist/client/manifest.json               4.62 KiB                                                                           10:46:04
../.nuxt/dist/client/404-9392f2b4.mjs            0.66 KiB / gzip: 0.43 KiB                                                          10:46:04
../.nuxt/dist/client/about-77de8eae.mjs          7.62 KiB / gzip: 1.99 KiB                                                          10:46:04
../.nuxt/dist/client/login-712d7e7b.mjs          2.34 KiB / gzip: 1.08 KiB                                                          10:46:04
../.nuxt/dist/client/register-25f056ac.mjs       3.37 KiB / gzip: 1.30 KiB                                                          10:46:04
../.nuxt/dist/client/restPassword-b31fe07d.mjs   1.51 KiB / gzip: 0.78 KiB                                                          10:46:04
../.nuxt/dist/client/contact-40a4575f.mjs        4.40 KiB / gzip: 1.35 KiB                                                          10:46:04
../.nuxt/dist/client/architecture-6f3afacd.mjs   0.17 KiB / gzip: 0.16 KiB                                                          10:46:04
../.nuxt/dist/client/devops-7de8583f.mjs         0.17 KiB / gzip: 0.16 KiB                                                          10:46:04
../.nuxt/dist/client/vpn-ee81118d.mjs            0.17 KiB / gzip: 0.16 KiB                                                          10:46:04
../.nuxt/dist/client/detail-e1e2a1d8.mjs         5.06 KiB / gzip: 1.07 KiB                                                          10:46:04
../.nuxt/dist/client/jobs-eeba6594.mjs           0.17 KiB / gzip: 0.16 KiB                                                          10:46:04
../.nuxt/dist/client/index-80b4b2c1.mjs          14.12 KiB / gzip: 2.82 KiB                                                         10:46:04
../.nuxt/dist/client/user-397fca42.mjs           8.42 KiB / gzip: 2.47 KiB                                                          10:46:04
../.nuxt/dist/client/payment-1422b033.mjs        12.80 KiB / gzip: 3.02 KiB                                                         10:46:04
../.nuxt/dist/client/privacy-94beed27.mjs        4.34 KiB / gzip: 1.85 KiB                                                          10:46:04
../.nuxt/dist/client/terms-0dbde4d5.mjs          5.89 KiB / gzip: 2.15 KiB                                                          10:46:04
../.nuxt/dist/client/auth-128b0ae8.mjs           1.87 KiB / gzip: 0.94 KiB                                                          10:46:04
../.nuxt/dist/client/default-4311ca38.mjs        9.25 KiB / gzip: 2.35 KiB                                                          10:46:04
../.nuxt/dist/client/default.e2a612cf.css        0.62 KiB / gzip: 0.29 KiB                                                          10:46:04
../.nuxt/dist/client/auth.51416dac.css           0.40 KiB / gzip: 0.25 KiB                                                          10:46:04
../.nuxt/dist/client/recruitment-242cb42b.mjs    13.68 KiB / gzip: 3.75 KiB                                                         10:46:04
../.nuxt/dist/client/entry.a4ff7230.css          15.29 KiB / gzip: 3.61 KiB                                                         10:46:04
../.nuxt/dist/client/entry-8f86bb9c.mjs          141.47 KiB / gzip: 52.09 KiB                                                       10:46:04
ℹ Client built in 3625ms                                                                                                            10:46:04
ℹ Building server...                                                                                                                10:46:04
vite v2.9.9 building SSR bundle for production...                                                                                   10:46:04

 WARN  @nuxtjs/sentry doesn't appear to be written in CJS, but also doesn't appear to be a valid ES module (i.e. it doesn't have "type": "module" or an .mjs extension for the entry point). Please contact the package author to fix.

✓ 181 modules transformed.                                                                                                          10:46:05
../.nuxt/dist/server/server.mjs   315.12 KiB                                                                                        10:46:05
✔ Server built in 1194ms                                                                                                            10:46:05
✔ Generated public .output/public                                                                                             nitro 10:46:05
start Building server...                                                                                                      nitro 10:46:05
start Writing server bundle...                                                                                                nitro 10:46:09
✔ Server built                                                                                                                nitro 10:46:10
  ├─ .output/server/package.json (696 B) (318 B gzip)
  ├─ .output/server/index.mjs.map (105 B) (100 B gzip)
  ├─ .output/server/index.mjs (398 B) (228 B gzip)
  ├─ .output/server/chunks/vue3.mjs.map (384 B) (257 B gzip)
  ├─ .output/server/chunks/vue3.mjs (317 B) (226 B gzip)
  ├─ .output/server/chunks/nitro/static.mjs.map (2.92 kB) (633 B gzip)
  ├─ .output/server/chunks/nitro/static.mjs (28.6 kB) (4.54 kB gzip)
  ├─ .output/server/chunks/nitro/node-server.mjs.map (15.5 kB) (2.86 kB gzip)
  ├─ .output/server/chunks/nitro/node-server.mjs (12.6 kB) (4.13 kB gzip)
  ├─ .output/server/chunks/index.mjs.map (1.81 MB) (84.2 kB gzip)
  ├─ .output/server/chunks/index.mjs (405 kB) (92.2 kB gzip)
  ├─ .output/server/chunks/handlers/renderer.mjs.map (30.1 kB) (4.84 kB gzip)
  ├─ .output/server/chunks/handlers/renderer.mjs (23.6 kB) (6.52 kB gzip)
  ├─ .output/server/chunks/app/server.mjs.map (328 kB) (42.5 kB gzip)
  ├─ .output/server/chunks/app/server.mjs (469 kB) (87.4 kB gzip)
  ├─ .output/server/chunks/app/client.manifest.mjs.map (3.98 kB) (635 B gzip)
  └─ .output/server/chunks/app/client.manifest.mjs (4.84 kB) (800 B gzip)
Σ Total size: 5.94 MB (984 kB gzip)
✔ You can preview this build using node .output/server/index.mjs 

Describe the bug

run node .output/server/index.mjs

errors

[nitro] Error while generating error response FetchError: 404  (/__nuxt_error?url=/_nuxt/__vite_ping&statusCode=404&statusMessage=Cannot+find+static+asset+/_nuxt/__vite_ping&message=Cannot+find+static+asset+/_nuxt/__vite_ping&description)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.errorhandler [as onError] (file:///Users/sheilar.gonzalez/WebstormProjects/global_cloud_nuxt3/.output/server/chunks/nitro/node-server.mjs:310:16)
    at async Server.nodeHandler (file:///Users/sheilar.gonzalez/WebstormProjects/global_cloud_nuxt3/.output/server/node_modules/h3/dist/index.mjs:370:9)

Additional context

refer issue : https://github.com/antfu/vitesse-nuxt3/issues/40

No response

Logs

No response

nooperpudd avatar May 12 '22 04:05 nooperpudd

same problems

andysay avatar May 12 '22 07:05 andysay

Would you please provide a minimal reproduction? 🙏

danielroe avatar May 12 '22 09:05 danielroe

Would you please provide a minimal reproduction? 🙏

Hi @danielroe, you can directly check this link, https://github.com/antfu/vitesse-nuxt3/issues/40. just clone the repo, and run npm build. then run in production node .output/server/index.mjs

nooperpudd avatar May 12 '22 11:05 nooperpudd

I actually cannot reproduce it with that repo.

danielroe avatar May 13 '22 13:05 danielroe

I actually cannot reproduce it with that repo.

I just updated the node version to v16.15.0 and updated the nuxt to the latest version. kindly the issue seems to be resolved.

nooperpudd avatar May 14 '22 10:05 nooperpudd

I actually cannot reproduce it with that repo.

I just updated the node version to v16.15.0 and updated the nuxt to the latest version. kindly the issue seems to be resolved.

my error still have also updated to 16.15.0 Снимок экрана 2022-05-15 в 07 29 36

andysay avatar May 15 '22 04:05 andysay

npm cache clean --force fix it.

andysay avatar May 15 '22 05:05 andysay

Same issue on production build. If I add custom pages/404.vue with content

<template>
    <div>
        <h1>My 404 page</h1>
    </div>
</template>

npm cache clean --force doesn't help

nuxt version 3.0.0-rc.3 node version v17.9.0 (same issue on v16.15.0 and 18)

Reproduction steps:

  • Create new Nuxt app
  • Delete app.vue
  • Create /pages
  • Create /pages/index.vue
  • Create/pages/404.vue
  • Build: npm run build
  • Run build: node .output/server/index.mjs

@danielroe, please reopen the issue

alehano avatar May 16 '22 04:05 alehano

~@alehano I can't reproduce it. See repo.~

Edit: Actually, I see it's not any 404, it's just hitting http://localhost:3000/_nuxt/__vite_ping or other missing static asset.

danielroe avatar May 16 '22 09:05 danielroe

Ok. On my local machine I still get this error on any 404 paths. But only on production build.

alehano avatar May 16 '22 10:05 alehano

~@alehano I can't reproduce it. See repo.~

Edit: Actually, I see it's not any 404, it's just hitting http://localhost:3000/_nuxt/__vite_ping or other missing static asset.

I started receiving these errors seemingly randomly. This thread pointed me to 404.vue being an issue. Then I realized a missing favicon.ico is triggering the 404 and the error.

[Vue warn]: Unhandled error during execution of setup function 
  at <404 onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > key="/favicon.ico" >
[nuxt] [request error] document is not defined
  at setup (./.nuxt/dist/server/server.mjs:36928:20)  
  at _sfc_main.setup (./.nuxt/dist/server/server.mjs:37087:23)  
  at callWithErrorHandling (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)  
  at setupStatefulComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7027:29)  
  at setupComponent (./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6982:11)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:198:17)  
  at renderVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:310:22)  
  at renderVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:316:17)  
  at renderComponentSubTree (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:275:13)  
  at renderComponentVNode (./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:214:16)
[nitro] Error while generating error response FetchError: 404  (/__nuxt_error?url=/favicon.ico&statusCode=500&statusMessage=Internal+Server+Error&message=document+is+not+defined&description=%3Cpre%3E%3Cspan+class=%22stack%22%3Eat+setup+(./.nuxt/dist/server/server.mjs:36928:20)%3C/span%3E%0A%3Cspan+class=%22stack%22%3Eat+_sfc_main.setup+(./.nuxt/dist/server/server.mjs:37087:23)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+callWithErrorHandling+(./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+setupStatefulComponent+(./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7027:29)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+setupComponent+(./node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6982:11)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+renderComponentVNode+(./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:198:17)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+renderVNode+(./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:310:22)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+renderVNode+(./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:316:17)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+renderComponentSubTree+(./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:275:13)%3C/span%3E%0A%3Cspan+class=%22stack+internal%22%3Eat+renderComponentVNode+(./node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:214:16)%3C/span%3E%3C/pre%3E&data)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.errorhandler [as onError] (file:///home/brandon/projects/nuxconf-starter/.nuxt/dev/index.mjs:307:16)
    at async Server.nodeHandler (file:///home/brandon/projects/nuxconf-starter/node_modules/h3/dist/index.mjs:370:9)

Ok. On my local machine I still get this error on any 404 paths. But only on production build.

I removed my 404.vue page and the errors are gone and replaced with

[Vue Router warn]: No match found for location with path "/favicon.ico"
[Vue Router warn]: No match found for location with path "/favicon.ico"
...

npm cache or node version were not the issue. Currently using 16.14.2

brandonratz avatar May 25 '22 01:05 brandonratz

same issue

oceanlvr avatar Jun 19 '22 15:06 oceanlvr

Had the same issue. Removed 404.vue and now running production server works fine

nedas-dev avatar Jun 21 '22 21:06 nedas-dev

Same problem for me. I tried to remove 404.vue, but I still have the same error

eMeRiKa13 avatar Jun 24 '22 15:06 eMeRiKa13

Confirmed. I decided to customize the 404 page, added the /pages/404.vue file, which contains only the template and styles, and now I get this error in the production build. Nuxt rc.4 Node v16.13.2

miker059 avatar Jul 08 '22 13:07 miker059

Confirmed. I decided to customize the 404 page, added the /pages/404.vue file, which contains only the template and styles, and now I get this error in the production build. Nuxt rc.4 Node v16.13.2

I am testing the vitesse-nuxt3 starter template and I can confirm that adding a div in the 404 page as a root element around the content fixed the issue.

<div>
  <main>
    ....
  </main>
</div>

szvest avatar Jul 12 '22 12:07 szvest

Confirmed. I decided to customize the 404 page, added the /pages/404.vue file, which contains only the template and styles, and now I get this error in the production build. Nuxt rc.4 Node v16.13.2

I am testing the vitesse-nuxt3 starter template and I can confirm that adding a div in the 404 page as a root element around the content fixed the issue.

<div>
  <main>
    ....
  </main>
</div>

It feels very unstable. Now that I've just edited another page, the error is back again.

szvest avatar Jul 12 '22 16:07 szvest

Similar issue here. Only happens in production, but occurs at server start (yarn run build && yarn run nuxi start).

  • Yarn v1.22.19
  • Node v16.16.0
  • Nuxt v3.0.0-rc.5
  • Ubuntu 18.04.6 LTS
$ /home/main-website/node_modules/.bin/nuxi start
Nuxt CLI v3.0.0-rc.5                                                                                                                              17:17:24
ℹ Node.js version: 16.16.0                                                                                                                        17:17:24
ℹ Preset: node-server                                                                                                                             17:17:24
ℹ Working dir: .output                                                                                                                            17:17:24
ℹ Loading .env. This will not be loaded when running the server in production.                                                                    17:17:24
ℹ Starting preview command: node ./server/index.mjs                                                                                               17:17:24
                                                                                                                                                  17:17:24
Listening on http://0.0.0.0:3000/
[nitro] Error while generating error response FetchError: 302  (/__nuxt_error?url=/_nuxt/__vite_ping&statusCode=404&statusMessage=Cannot+find+static+asset+/_nuxt/__vite_ping&message=Cannot+find+static+asset+/_nuxt/__vite_ping&description&data)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.errorhandler [as onError] (file:///home/main-website/.output/server/chunks/nitro/node-server.mjs:321:16)
    at async Server.nodeHandler (file:///home/main-website/.output/server/node_modules/h3/dist/index.mjs:373:9)
[nitro] Error while generating error response FetchError: 302  (/__nuxt_error?url=/_nuxt/__vite_ping&statusCode=404&statusMessage=Cannot+find+static+asset+/_nuxt/__vite_ping&message=Cannot+find+static+asset+/_nuxt/__vite_ping&description&data)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.errorhandler [as onError] (file:///home/main-website/.output/server/chunks/nitro/node-server.mjs:321:16)
    at async Server.nodeHandler (file:///home/main-website/.output/server/node_modules/h3/dist/index.mjs:373:9)
[nitro] Error while generating error response FetchError: 302  (/__nuxt_error?url=/_nuxt/__vite_ping&statusCode=404&statusMessage=Cannot+find+static+asset+/_nuxt/__vite_ping&message=Cannot+find+static+asset+/_nuxt/__vite_ping&description&data)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

If I try to request that page (http://localhost:3000//__nuxt_error?url=/_nuxt/__vite_ping&statusCode=404&statusMessage=Cannot+find+static+asset+/_nuxt/__vite_ping&message=Cannot+find+static+asset+/_nuxt/__vite_ping&description&data) it's complaining about directly, from a dev environment (same server), it says it cannot be found (404) and I see this in the console log:

[Vue Router warn]: No match found for location with path "/_nuxt/__vite_ping"

clairegraham avatar Jul 14 '22 17:07 clairegraham

Same error only in production environment,how to solve it?

itancc avatar Jul 17 '22 03:07 itancc

I got the same error. After some debugging, I found it happened because I run the dev server and then open the browser, I think the browser calling "__vite_ping" periodically. So when I run the production build "nuxt start", the browser still calls "__vite_ping", but because there is no such thing on the production, the server logs the error. If I refresh the browser, the error is gone.

jurgel avatar Jul 20 '22 03:07 jurgel

after closing and opening the browser and clearing the cache, the error is gone. it think the issue is caused by the browser.

jonmes avatar Aug 05 '22 11:08 jonmes

Same here, removing pages/404.vue fixed the issue in production.

rmenai avatar Aug 05 '22 22:08 rmenai

I believe this has been resolved now. @pi0 feel free to reopen if there's a reason you want to keep this open.

danielroe avatar Aug 18 '22 08:08 danielroe