vuetifyjs / nuxt-module

Zero-config Nuxt Module for Vuetify
https://nuxt.vuetifyjs.com/
MIT License
226 stars 22 forks source link

Parsing error when using a vuetify locale #222

Closed eiggiotti closed 7 months ago

eiggiotti commented 7 months ago

Hi!

I've encountered a bug while trying to use the vuetify french locale with this config:

import { fr } from 'vuetify/locale';

export default defineNuxtConfig({
  devtools: { enabled: false },
  modules: ['vuetify-nuxt-module'],
  vuetify: {
    vuetifyOptions: {
      locale: {
        locale: 'fr',
        messages: { fr },
      },
    },
  },
});

The console gives this error:

 ERROR  Pre-transform error: Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.

And the page displays this error: image

I've created this stackblitz to see the bug for yourself.

The problem seems to come from this code:

        return `${result.imports}

export const isDev = ${ctx.isDev}
export function vuetifyConfiguration() {
  const options = JSON.parse('${JSON.stringify(newVuetifyOptions)}')
  ${result.directives}
  ${result.aliases}
  ${result.components}
  ${result.messages}
  return options
}
${deepCopy
  ? `function deepCopy(src,des) {
    for (const key in src) {
      if (typeof src[key] === 'object') {
        if (typeof des[key] !== 'object') des[key] = {}
        deepCopy(src[key], des[key])
      } else {
        des[key] = src[key]
      }
    }
  }
  `
  : ''
}
`

When newVuetifyOptions contains a single quote character, as it is the case when using the french locale, the generated code is no longer valid.

userquin commented 7 months ago

@eiggiotti I'm fixing the configuration when providing locale.messages (in the meantime, if you are using only fr entries you can remove messages entry and the import and use localeMessages instead):

    vuetifyOptions: {
      locale: {
        locale: 'fr',
      },
      localeMessages: ['fr'],
    },
eiggiotti commented 7 months ago

Thank you @userquin, that fixes it!