nolebase / integrations

✍️ A collection of diverse documentation engineering tools. Better reading experience, inline link preview, highlight targeted title, enhanced <mark> element, state-of-the-art SEO and <meta> generation, og image, thumbhash & blurhash images and more!
https://nolebase-integrations.ayaka.io
MIT License
106 stars 20 forks source link

Build failed with `Link Preview` Plugin #251

Closed Kutius closed 4 days ago

Kutius commented 3 weeks ago

config:

// defineconfig...
  markdown: {
    config: (md) => {
      md.use(InlineLinkPreviewElementTransform)
    },
    theme: {
      light: 'light-plus',
      dark: 'dark-plus',
    },
    codeTransformers: [
      transformerTwoslash(),
    ],
  },

// theme/index.ts
  enhanceApp({ app, router, siteData }) {
    app.use(TwoslashFloatingVue)
    app.use(NolebaseGitChangelogPlugin)
    app.use(NolebaseInlineLinkPreviewPlugin)
    app.provide(InjectionKey, {
      spotlight: {
        defaultToggle: true,
      },
    })
    // ...
  },

output:

Unknown file extension ".vue" for /home/i/wiki/node_modules/@nolebase/vitepress-plugin-inline-link-preview/dist/client/components/InlineLinkPreview.vue
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".vue" for /home/i/wiki/node_modules/@nolebase/vitepress-plugin-inline-link-preview/dist/client/components/InlineLinkPreview.vue
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:396:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:45)
error: script "docs:build" exited with code 1

It looks like an SSG configuration error.

nekomeowww commented 3 weeks ago

Do you have a minimal reproduction that I can dig into?

What was your Vite config, VitePress config and theme config?

Kutius commented 3 weeks ago

@nekomeowww Maybe I found the key

This is Vite config:

  vite: {
    plugins: [
      Unocss(),
      GitChangelog({
        // 填写在此处填写您的仓库链接
        repoURL: () => 'https://xxx.com/knowledge/wiki/tree/@next-vitepress',
        getCommitURL: commit => `${commit.repo_url?.replace('/tree/@next-vitepress', '')}/commit/${commit.hash}`,
      }),
      GitChangelogMarkdownSection(),
    ],
    optimizeDeps: {
      exclude: [
        '@nolebase/vitepress-plugin-enhanced-readabilities/client',
      ],
    },
    ssr: {
      noExternal: [
        // 如果还有别的依赖需要添加的话,并排填写和配置到这里即可
        '@nolebase/vitepress-plugin-enhanced-readabilities',
      ],
    },
  },

When I replace the value in ssr noEXternal

'@nolebase/vitepress-plugin-enhanced-readabilities'

to

'@nolebase/*'

And then get no error

cosmic-jellyfish commented 2 weeks ago

Just chiming in here, doing the solution mentioned above works.

Original error:

vitepress v1.3.0

✓ building client + server bundles...
build error:
Unknown file extension ".vue" for E:\Users\cake\Desktop\Test\node_modules\@nolebase\vitepress-plugin-inline-link-preview\dist\client\components\PopupIframe.vue
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".vue" for E:\Users\cake\Desktop\Test\node_modules\@nolebase\vitepress-plugin-inline-link-preview\dist\client\components\PopupIframe.vue
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:396:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:45)

Was the error given

However using this config:

   vite: {
    optimizeDeps: {
      exclude: [
        '@nolebase/vitepress-plugin-inline-link-preview/markdown-it',
      ],
    },
    ssr: {
      noExternal: [
        '@nolebase/*',
      ],
    },
  },

has made it work.

I originally had either no config placed (testing purposes) or with @nolebase/vitepress-plugin-inline-link-preview/markdown-it placed in the ssr caused the error.

nekomeowww commented 2 weeks ago

Sorry for the delay, I was in Hackathon last week and we had no time to focus on Nolebase communities. Apologize for the delay, really!

Please, much appriciated if any of you would like to take a look into this, a documentation contribution to mention this out is welcome too!

nekomeowww commented 1 week ago

Possibly related to https://github.com/nolebase/nolebase/issues/59

nekomeowww commented 4 days ago

Adding @nolebase/vitepress-plugin-inline-link-preview into ssr. noExternal would solve this.