slidev icon indicating copy to clipboard operation
slidev copied to clipboard

Unexpected Execution Failure Due to Missing @slidev/types Reference in Vite Config

Open sghng opened this issue 11 months ago • 3 comments

Describe the bug

When configuring Slidev in vite.config.ts, the slidev configuration option is not recognized unless @slidev/types is explicitly referenced. This leads to an unexpected failure where slides do not render properly in Slidev, even though TypeScript types should not normally affect execution.

This appeared in the addon I'm working on and is now addressed: https://github.com/sghuang19/slidev-addon-prime.

Minimal reproduction

Steps to reproduce the behavior:

  1. Setup a project with this vite.config.ts
import { defineConfig } from "vite";
import { PrimeVueResolver } from "@primevue/auto-import-resolver";

export default defineConfig({
  slidev: {
    components: {
      resolvers: [PrimeVueResolver()],
    },
  },
});
  1. In some cases, Slidev recognizes slidev as a valid config option and works fine. Presumably due to caching or the order of package installation. However, in my case, when cloning the code into new dir, the slidev option is not recognized.
  2. Run slidev, the slides are not rendered (empty screen, no error msg) Environment
  3. Adding this line to the top of config file solves it:
/// <reference types="@slidev/types" />
  • Slidev version: v51.1.0
  • Browser: Arc
  • OS: macOS Sonoma
  • Runtime: Bun v1.2.2

Proposed solutions

  • Add a note to the documentation first.
  • Investigate the @slidev/types package. Some of the types should be exposed explicitly.

sghng avatar Feb 02 '25 03:02 sghng

I think @slidev/types has to be explicitly imported to make the types being recognized, because TypeScript requires to do so.

For the runtime error, I cannot understand why, because type information should not be able to affect runtime behavior. Could you provide some error messages of the runtime error? (If I understand the issue correctly)

kermanx avatar Feb 21 '25 14:02 kermanx

I think @slidev/types has to be explicitly imported to make the types being recognized, because TypeScript requires to do so.

For the runtime error, I cannot understand why, because type information should not be able to affect runtime behavior. Could you provide some error messages of the runtime error? (If I understand the issue correctly)

If I remembered correctly I didn't get any runtime error (otherwise i would've included them and at least had some clues)

A better way of doing the Vite config is allow us to import { defineViteConfig } from "@slidev/types", which validates the Slidev configs.

sghng avatar Feb 21 '25 17:02 sghng

A better way of doing the Vite config is allow us to import { defineViteConfig } from "@slidev/types", which validates the Slidev configs.

That's a nice idea.

kermanx avatar Feb 22 '25 01:02 kermanx