2

Running npm run start & npm run dev is producing different outcomes in my code. I intend to run the code in production to make it work as it does in development, however when I ran them respectively, is not rendering as intended. I have attached codes and screenshot to the code and rendered view.

Code Reference:

Dropdown Section

  <v-list-group>
    <template v-slot:activator>
      <v-list-item-content>
        <v-list-item-title>About Us</v-list-item-title>
      </v-list-item-content>
    </template>

    <v-list-item
      v-for="(item, index) in navItems[2].content"
      :key="index"
      :to="item.link"
    >
      <v-list-item-title v-text="item.name"></v-list-item-title>
    </v-list-item>
  </v-list-group>

    
navItems: [
{name: '', link: '', content: [{name: '', link: ''}]},{}{
{name: '', link: '', content: [{name: '', link: ''}]},
name: "aboutus",
      link: "",
      content: [
            { name: "Vision", link: "/about/vision" },
            { name: "Partner With Us", link: "/about/partnership" },
          ],
}]

Image Card Section

<v-card
  nuxt
  id="btn-home-forest"
  to="/industry/forestry"
  class="mx-0 bgMidPurple borderSharpTopBtmRound pb-3"
  max-width="276"
>
  <v-img
    :src="require('~/assets/images/forestry_button.png')"
    height="208px"
  ></v-img>

  <v-card-title
    class="textWhite textBody"
  >
    Forestry
  </v-card-title>

</v-card>

Nuxt Config JS

import colors from 'vuetify/es5/util/colors'

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  generate: {
    exclude: ['/blog', '/pricing'],
    fallback: '404.html'
  },
  target: 'static',
  server: {
    host: '0.0.0.0',
    port: 8888
  },
  head: {
    titleTemplate: '%s',
    title: 'nuxt-vuetify-basic',
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/EoF-Logo.png' }
    ],
  },
  env:{
  },
  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    '@assets/global.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [ 
    '@plugins/vue-recaptcha-v3.js',
    '@/plugins/vuelidate',
    '@/plugins/vue-country-code'
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    '@nuxtjs/vuetify',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    '@nuxtjs/axios', 'cookie-universal-nuxt'
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    baseURL: '/',
  },
  router:{
    //middleware: ['']
  },

  // Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
  vuetify: {
    treeShake: false,
    theme: {
      dark: true,
      themes: {
        dark: {
          primary: colors.blue.darken2,
          accent: colors.grey.darken3,
          secondary: colors.amber.darken3,
          info: colors.teal.lighten1,
          warning: colors.amber.base,
          error: colors.deepOrange.accent4,
          success: colors.green.accent3,
        },
      },
    },
  },
  build: {
    publicPath: '/public',
    filenames: {
      chunk: 'js/[id].[contenthash].js'
    },
    extractCSS: true,
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    },
    transpile: [
      'vuetify/lib',
    ],
  },
}

Production Config

Production Environment

Production Dropdown

Production Dropdown

Production Image Card

Production Image Card

Production Console Error Code Error Code in Prod

Development Config

Development Environment

Development Dropdown

Dev Dropdown

Development Image Card

Dev Image Card

Development Console Error Code Error Code in Dev

Why are the component breaking in production environment as compared to dev, when they are both running the same code?

I have referred to the following links below to troubleshoot the issue I'm facing in which could possibly be the closest to what I'm facing but it doesn't work either.

Nuxt production mode loading resources late?

Why is my Vue JS Nuxt lazy loaded component bundled in app.js, not loaded separately?

Tyler
  • 604
  • 3
  • 10
  • 24
  • You have a table which is missing a `TBODY` tag. – IVO GELOV Jun 27 '22 at 07:02
  • How does the Nuxt config look like in regards to rendering mode? What is the value of ssr and target? Is this it? As seen from the screenshots. `ssr: true, target: 'static',` – Kunukn Jun 27 '22 at 07:30
  • @Kunukn thanks for looking into this. I updated the question to include the nuxt config. Have a look – Tyler Jun 27 '22 at 07:39
  • If you have it as SSG (`target: 'static'`), you should then `npm run generate` and `npm run start` on Vercel/Netlify or any static platform. – kissu Jun 27 '22 at 08:19
  • Before going any further, I of course recommend fixing the DOM mismatch (quite a big deal tbh): https://stackoverflow.com/a/67978474/8816585 – kissu Jun 27 '22 at 08:23
  • @kissu thanks I'm looking into fixing the virtual dom issue, which is printing the missing tag error. Which has something to do with vue hydration... Looking into that. But the virtual dom error is from my dev env, which is not my concern now. – Tyler Jun 27 '22 at 08:49
  • additionally, i have tried both `npm run build` / `npm run generate` . Followed by `npm run start`. Both of which lead to the same production view error – Tyler Jun 27 '22 at 08:52
  • DOM mismatch should be a prio overall, and could also explain Vuetify's bug, especially since you're missing things. It may behave differently in production mode, hence the bug that you see. As told above, you should use `generate` and **NOT** `build`. Don't try both, use the correct one (SSG in your case, not SSR). So, how to solve this: 1. fix the DOM mismatch, 2. generate the project locally, 3. host it on https://netlify.com/drop to see if you still have the issue. 4. if you do, please come back here with a [repro] or more details overall. Good luck! – kissu Jun 27 '22 at 09:11
  • @kissu The error has resolved in production. However it wasn't because I was missing a tag or something though. I added clientOnly tag to it and it work. – Tyler Jun 27 '22 at 10:10
  • If you don't mind not having any SSG for the part nested inside of `client-only`, you can indeed proceed. The error given does it's best to explain the issue but it's not that easy to explain what may be the cause of a mismatch. – kissu Jun 27 '22 at 10:14

2 Answers2

1

OP solved the issue by wrapping his content inside of a client-only tag to prevent the DOM mismatch. More details could be found on my previous answer.

Also, keep in mind that this will not render the nested part on the server (during build time).

kissu
  • 40,416
  • 14
  • 65
  • 133
  • 1
    I added the code, producing the error above. Honestly, not sure why that component is producing the DOM mismatch. – Tyler Jun 27 '22 at 10:31
0

Thanks to Kissu for pointing out the significance of fixing the DOM mismatch. Followed the article/answer provided

Original Code with Error

<v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
       class="mx-md-3 mx-1 my-2"
    >
    <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
  </v-slide-item>

Fixed to code causing error

 <client-only>
    <v-slide-item
      v-for="item in tabTwoRange"
      :key="item"
      class="mx-md-3 mx-1 my-2"
    >
      <v-btn v-text="`• ${item}`" @click="TabTwo = item" :color="TabTwo === item ? 'textPurple' : 'textBlack'" class="bgWhite elevation-0 textBtn">-{{item}}</v-btn>
    </v-slide-item>
 </client-only>

Followed the following link to troubleshoot & pin point to the exact DOM element producing the error.

Tyler
  • 604
  • 3
  • 10
  • 24
  • I'm not sure about this exact component but maybe it's not SSR friendly (happens). Or maybe `tabTwoRange` is something that is only to be fetched on client side? I know that Vuetify is still in beta for Vue3 so maybe this is on their roadmap or maybe they are focusing on the Vue3 version rather. Anyway, maybe drop an issue there! – kissu Jun 27 '22 at 11:15