Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined route in Nuxt layout component in prod build #15434

Closed
misaon opened this issue Nov 10, 2022 · 29 comments · Fixed by #18626
Closed

Undefined route in Nuxt layout component in prod build #15434

misaon opened this issue Nov 10, 2022 · 29 comments · Fixed by #18626
Assignees

Comments

@misaon
Copy link
Contributor

misaon commented Nov 10, 2022

Environment

- Operating System: `Linux`
- Node Version:     `v16.18.0`
- Nuxt Version:     `3.0.0-rc.13`
- Nitro Version:    `0.6.1`
- Package Manager:  `pnpm@7.15.0`
- Builder:          `vite`
- User Config:      `modules`, `oxyshopNuxt`, `i18n`, `experimental`
- Runtime Modules:  `normalizedModule()`, `normalizedModule()`
- Build Modules:    `-`

Reproduction

Build to prod

Describe the bug

In the dev environment everything works fine, once the application build to production. on the client side Nuxt RC-13 crashes on the error that the route is undefined.
https://github.com/nuxt/framework/blob/59d8c51b5bd8d8f7de66f83494d9d39110e43c44/packages/nuxt/src/app/components/layout.ts#L73
On Nuxt RC-12 it works fine.

Additional context

image

Logs

TypeError: Cannot read properties of undefined (reading 'meta')
    at zc.fn (entry.6b774f36.js:78:63198)
    at zc.run (entry.6b774f36.js:1:4282)
    at get value [as value] (entry.6b774f36.js:1:12410)
    at Proxy.<anonymous> (entry.6b774f36.js:78:63258)
    at fl (entry.6b774f36.js:1:15833)
    at St (entry.6b774f36.js:1:49906)
    at zc.V [as fn] (entry.6b774f36.js:1:49994)
    at zc.run (entry.6b774f36.js:1:4282)
    at G.T.update (entry.6b774f36.js:1:50299)
    at G (entry.6b774f36.js:1:50325)
nE @ entry.6b774f36.js:1
@danielroe
Copy link
Member

Would you provide a reproduction? 🙏

@misaon
Copy link
Contributor Author

misaon commented Nov 10, 2022

Would you provide a reproduction? 🙏

Unfortunately, it's part of a commercial project.
It happened after we switched from RC-12 to RC-13. We are currently fixing to RC-12, hopefully we can fix the problem.

@misaon

This comment was marked as off-topic.

@danielroe
Copy link
Member

I'm not asking for your full app, just a minimal reproduction of the issue via https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz.

@misaon

This comment was marked as outdated.

@misaon

This comment was marked as resolved.

@misaon misaon changed the title Undefined route in Nuxt layout component Undefined route in Nuxt layout component in prod build Nov 10, 2022
@misaon
Copy link
Contributor Author

misaon commented Nov 10, 2022

const route falls to undefined in prod

@misaon
Copy link
Contributor Author

misaon commented Nov 11, 2022

Would you provide a reproduction? 🙏

#15443

@danielroe
Copy link
Member

Would you try upgrading your version of vue-router to 4.1.6 manually?

@michealroberts
Copy link

@danielroe Confirmed that upgrading to vue-router version 4.1.6 has fixed this issue. 🙏

@dargmuesli
Copy link
Member

I am on v4.1.6 since it was released and yet I still face this error on Nuxt edge.

@danielroe
Copy link
Member

danielroe commented Nov 14, 2022

@dargmuesli Any chance of a reproduction? 🙏 (The only example I have so far is using 4.1.5.)

@dargmuesli
Copy link
Member

dargmuesli commented Nov 14, 2022

Oh well, I spent way too many hours deep inside code just to find out I had to update my vue dependency to at least 3.2.45! The error is gone now.

@misaon
Copy link
Contributor Author

misaon commented Nov 14, 2022

Oh well, I spent way too many hours deep inside code just to find out I had to update my vue dependency to at least 3.2.45! The error is gone now.

Does it really work?

@misaon
Copy link
Contributor Author

misaon commented Nov 15, 2022

For me vue 3.2.45 and vue-router 4.1.6 still throw an error with an undefined route.

Copy link
Member

Please do provide a reproduction if that's the case. This is an upstream issue (not directly caused by Nuxt) but if there's anything I can do to help resolve this, I will.

@dargmuesli
Copy link
Member

Make sure all your other dependencies are up to date as well, @misaon.
If you're using pnpm that would be a pnpm upgrade --interactive --latest and a pnpm upgrade.

@paolooo
Copy link

paolooo commented Nov 16, 2022

What I did is to resolve this issue is, I deleted my yarn.lock file, node_modules, .output, and .nuxt directories. Then, installed nuxt again.

$ rm -rf node_modules .output .nuxt yarn.lock
$ yarn install
$ yarn build
$ node .output/server/index.mjs

@misaon
Copy link
Contributor Author

misaon commented Nov 16, 2022

Upgrade to RC-14 solved this issue 🙏

@misaon misaon closed this as completed Nov 16, 2022
@MichaelPrecel
Copy link

MichaelPrecel commented Nov 21, 2022

I didn't encounter this issue until upgrading from rc-12 to 1.0.0. In dev and in local build it works fine, but as soon as it is deployed to Netlify I'm hit with the error cannot read properties of undefined (reading 'meta'). The page loads for a split second and then the error is encountered and the page goes white.

Looking at pnpm-lock.yaml, vue router and vue are at the latest versions as above.

@danielroe Any ideas? Could it have something to do with the fact that this project only uses one template, ie the pages folder only contains two files [[slug]].vue and 404.vue? Still strange that it's only on production in Netlify that it's occuring.

Have had to revert to rc-12 in the meantime until resolved.

Screen Shot 2022-11-21 at 1 38 02 pm

@misaon
Copy link
Contributor Author

misaon commented Nov 21, 2022

I didn't encounter this issue until upgrading from rc-12 to 1.0.0. In dev and in local build it works fine, but as soon as it is deployed to Netlify I'm hit with the error cannot read properties of undefined (reading 'meta'). The page loads for a split second and then the error is encountered and the page goes white.

Looking at pnpm-lock.yaml, vue router and vue are at the latest versions as above.

@danielroe Any ideas? Could it have something to do with the fact that this project only uses one template, ie the pages folder only contains two files [[slug]].vue and 404.vue? Still strange that it's only on production in Netlify that it's occuring.

Have had to revert to rc-12 in the meantime until resolved.

Screen Shot 2022-11-21 at 1 38 02 pm

Show me your package.json deps list.

@littlejon85
Copy link

I didn't encounter this issue until upgrading from rc-12 to 1.0.0. In dev and in local build it works fine, but as soon as it is deployed to Netlify I'm hit with the error cannot read properties of undefined (reading 'meta'). The page loads for a split second and then the error is encountered and the page goes white.
Looking at pnpm-lock.yaml, vue router and vue are at the latest versions as above.
@danielroe Any ideas? Could it have something to do with the fact that this project only uses one template, ie the pages folder only contains two files [[slug]].vue and 404.vue? Still strange that it's only on production in Netlify that it's occuring.
Have had to revert to rc-12 in the meantime until resolved.
Screen Shot 2022-11-21 at 1 38 02 pm

Show me your package.json deps list.

I have an observation which might help to narrow it down a bit.
I encountered this issue also when going from rc.12 to ^rc.14 and 1.0.0. It only happened when using pnpm install --shamefully-hoist. Using npm didn't produce this problem.
The cause of it for me was our internal components library. It was enough for it to be included in package.json of a clean nuxt project. I'd get the error event without importing any part of it. Been trying to make a reproduction, but couldn't.
Adding auto-install-peers=true to .npmrc solved the issue.

@misaon
Copy link
Contributor Author

misaon commented Nov 21, 2022

One possible problem could be that one of your deps has a dependency on Vue 2. For example, the presence of the @gtm-support/vue-gtm package in package.json is causing this particular error.

@Katerinka28
Copy link

I didn't encounter this issue until upgrading from rc-12 to 1.0.0. In dev and in local build it works fine, but as soon as it is deployed to Netlify I'm hit with the error cannot read properties of undefined (reading 'meta'). The page loads for a split second and then the error is encountered and the page goes white.

Looking at pnpm-lock.yaml, vue router and vue are at the latest versions as above.

@danielroe Any ideas? Could it have something to do with the fact that this project only uses one template, ie the pages folder only contains two files [[slug]].vue and 404.vue? Still strange that it's only on production in Netlify that it's occuring.

Have had to revert to rc-12 in the meantime until resolved.

Screen Shot 2022-11-21 at 1 38 02 pm

just upgrate vue-router to 4.1.6! It`s work perfect for me(nuxt 3.0.0)

@MichaelPrecel
Copy link

Thanks everyone for your suggestions, a lot of good avenues to explore here. @misaon You could be on the money, I'm using vue-gtag-next, so perhaps that has a Vue 2 dep. I'll try See package below. I'll try some of these solutions and report back.

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "@vueuse/core": "^9.1.1",
    "@vueuse/nuxt": "^9.1.1",
    "include-media": "^1.4.10",
    "nuxt": "3.0.0-rc.12",
    "sass": "^1.51.0",
    "sass-loader": "^13.2.0"
  },
  "dependencies": {
    "@nuxtjs/sanity": "1.3.2",
    "@sanity/image-url": "^1.0.1",
    "flickity": "^3.0.0",
    "flickity-as-nav-for": "^3.0.0",
    "lazysizes": "^5.3.2",
    "reset-css": "^5.0.1",
    "vh-check": "^2.0.5",
    "vue-gtag-next": "^1.14.0"
  }
}

@victorgarciaesgi
Copy link

Hello! I'm still having the error on e2e tests fixtures. Strange thing is on fixture run correctly while the other fails. Exactly like said before, the content appears then disappears with the error.
I'm using @nuxt/test-utils
Repo here: https://github.com/victorgarciaesgi/nuxt-typed-router/tree/v2.1.3
Steps:

  • Go to test/e2e/complex.spec.ts and decomment all comments
  • Run pnpm run test

Tried auto-install-peers=true as @littlejon85 said but no luck

@victorgarciaesgi
Copy link

Also worth noting that I had the same problem with docs/docus, and fixed the problem by switching to yarn. But here even switching to yarn/npm didn't fixed the issue

@misaon
Copy link
Contributor Author

misaon commented Jan 30, 2023

@danielroe
I finally managed to create a reproduction of this infernal bug! https://stackblitz.com/edit/github-ecbwau?file=package.json

Steps:

  1. run $ pnpm install
  2. run $ pnpm run build
  3. run $ node .output/server/index.mjs

@misaon misaon reopened this Jan 30, 2023
@danielroe
Copy link
Member

The issue seems to be that @gtm-support/vue-gtm is pulling in a separate copy of vue-router.

For now you can workaround with:

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  vite: {
    resolve: {
      dedupe: ['vue-router']
    }
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants