slidevjs / slidev

Presentation Slides for Developers
https://sli.dev
MIT License
32.82k stars 1.33k forks source link

Addons does not resolve import correctly #1880

Closed Barbapapazes closed 1 week ago

Barbapapazes commented 1 week ago

Describe the bug

Hello 👋,

I'm building an addon for Slidev but I have the following issue:

slide failed to load SyntaxError: The requested module '/@fs/Users/esoub/dev/p/talks/node_modules/.pnpm/to-px@1.1.0/node_modules/to-px/browser.js?v=66bf5b78' does not provide an export named 'default'

This occurs when using the following syntax:

addons
    - my-addon # From npm

BUT it works correctly (no import issue) with the following syntax

addons:
    - ../../my-addon # From a local file (filesystem)

Minimal reproduction

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See the error

You can use https://sli.dev/new to create a new project to reproduce the issue.

Environment

If you are using Slidev globally (i.e. npx slidev or npm i -g slidev), please try to reproduce the issue in a local project (i.e. npm create slidev@latest).

Barbapapazes commented 1 week ago

It seems to be related to a commonjs dependencies: https://vitejs.dev/config/dep-optimization-options#optimizedeps-include:~:text=CommonJS,js

By using the following vite.config.js, it works:

import { defineConfig } from 'vite'

export default defineConfig({
  optimizeDeps: {
    include: [
      'my-addon > pusher-js',
      'my-addon > to-px',
      'my-addon > striptags',
    ],
  },
})