Search code examples
node.jsvue.jsnpmnuxt.jsprimevue

PrimeVue components issue with Nuxt Js


I installed my Nuxt application with the command "npx create-nuxt-app myapp", i choosed "Primevue" as my Ui framework, i try to print an component, but when i acces to the localhost page, it doesn't show nothing..

Do i need to configure more things? I get this error on console when i try to print a component Unknown custom element: <SelectButton> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

I expect to have my code working, i installed nuxt and the project is default with the UI framework, what more i should do?

I add my Nuxt.config.js file

    export default {
  // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
  ssr: false,

  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'socialApp',
    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: '/favicon.ico' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
      'primeflex/primeflex.css'
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [],


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

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

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // Doc: https://www.primefaces.org/primevue/showcase-v2/#/setup
    'primevue/nuxt',
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    // https://go.nuxtjs.dev/pwa
    '@nuxtjs/pwa',
  ],

  // Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {
    // Workaround to avoid enforcing hard-coded localhost:3000: https://github.com/nuxt-community/axios-module/issues/308
    baseURL: '/',
  },

  // PWA module configuration: https://go.nuxtjs.dev/pwa
  pwa: {
    manifest: {
      lang: 'en'
    }
  },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    // https://github.com/primefaces/primevue/issues/844
    transpile: ['primevue'],
  }
}

My node -v is 16.13.2 My npm -v is 8.1.2 My nuxt -v is 3.4.1

And my Package.json file

{
  "name": "socialApp",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "dev": "nuxt",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate"
  },
  "dependencies": {
    "@nuxtjs/axios": "^5.13.6",
    "@nuxtjs/pwa": "^3.3.5",
    "core-js": "^3.25.3",
    "nuxt": "^2.15.8",
    "primeflex": "^3.2.1",
    "primeicons": "^6.0.1",
    "primevue": "^2.10.1",
    "vue": "^2.7.10",
    "vue-server-renderer": "^2.7.10",
    "vue-template-compiler": "^2.7.10"
  }
}

Solution

  • Your nuxt config it's correctly, you will need to add the code on your page/componente, that way

    import { SelectButton } from 'primevue/selectbutton';
    
    export default {
      components: {
        SelectButton
    

    An way to do this it's create a plugin with this import do you want use, that's plugin, will use as all components / pages, like that way nuxt.config

    plugins: [ { src: '~/plugins/primevue.js', mode: 'client' }, ],