vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.26k stars 2.14k forks source link

error while integrate custom theme with PrimeVue #4192

Closed bingling-sama closed 2 months ago

bingling-sama commented 2 months ago

Describe the bug

When I import PrimeVue and configure it in the theme/index.ts file, I got a error:

4:34:33 PM [vitepress] Pre-transform error: Failed to resolve entry for package "primevue". The package may have incorrect main/module/exports specified in its package.json: Missing "." specifier in "primevue" package
4:34:33 PM [vitepress] Internal server error: Failed to resolve entry for package "primevue". The package may have incorrect main/module/exports specified in its package.json: Missing "." specifier in "primevue" package
  Plugin: vite:import-analysis

Reproduction

Create a vitepress project theme with custom theme:

pnpm add vitepress
pnpm vitepress init

choose all default but the Theme section:

◆  Theme:
│  ○ Default Theme (Out of the box, good-looking docs)
│  ○ Default Theme + Customization
│  ● Custom Theme

then add the PrimeVue lib:

pnpm add primevue @primevue/themes

use it in the theme/index.ts

// theme/index.ts
import Layout from './Layout.vue'
import type { Theme } from 'vitepress'
import './style.css'

import PrimeVue from "primevue"
import Aura from "@primevue/themes"

export default {
    Layout,
    enhanceApp({ app, router, siteData }) {
        // ...
        app.use(PrimeVue, {
            theme: {
                preset: Aura
            }
        })
    }
} satisfies Theme

then run pnpm docs:dev

Expected behavior

It should be running without any error, but i got a package error. It seems like there's some problem with vite:import-analysis

System Info

I tested in Arch and Windows

  System:
    OS: Linux 5.15 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 8845H w/ Radeon 780M Graphics
    Memory: 5.77 GB / 7.41 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.8.0 - ~/.local/share/pnpm/node
    npm: 10.8.2 - ~/.local/share/pnpm/npm
    pnpm: 9.10.0 - ~/.local/share/pnpm/pnpm
  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 8845H w/ Radeon 780M Graphics
    Memory: 4.74 GB / 15.30 GB
  Binaries:
    Node: 20.17.0 - E:\nodejs\node.EXE
    npm: 10.8.2 - E:\nodejs\npm.CMD
    pnpm: 9.10.0 - ~\AppData\Local\Microsoft\WinGet\Links\pnpm.EXE
  Browsers:
    Edge: Chromium (127.0.2651.86)
    Internet Explorer: 11.0.22621.3527


### Additional context

_No response_

### Validations

- [X] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).
- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)
- [X] Read the [docs](https://vitepress.dev).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
userquin commented 2 months ago

You should use import PrimeVue from 'primevue/config', check the docs https://github.com/primefaces/primevue/tree/master/packages/primevue#plugin