Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(4.1.0) Not handle build from other directory #380

Closed
3 tasks done
sarrooo opened this issue Sep 6, 2024 · 3 comments
Closed
3 tasks done

(4.1.0) Not handle build from other directory #380

sarrooo opened this issue Sep 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@sarrooo
Copy link

sarrooo commented Sep 6, 2024

Describe the bug

Description

I am using this plugin in a monorepo package :

.
└── my-monorepo/
    ├── apps
    └── libs/
        └── ui-library/
            ├── src/
            ├── ...
            ├── project.json
            ├── vite.config.ts
            ├── vitest.config.ts
            └── tsconfig.ts

I am trying to run the Vite build command from the root of the monorepo using the command pnpm run build:ui-library, which is equivalent to pnpm vite build -c libs/ui-library/vite.config.ts.

Bug

When using the dts plugin, I encounter errors stating that Vue modules cannot be found. For example:

libs/ui-library/src/components/index.ts:10:46 - error TS2307: Cannot find module '@/components/status/StatusMultiSelect/StatusMultiSelect.vue' or its corresponding type declarations.

10 export { default as StatusMultiSelect } from '@/components/status/StatusMultiSelect/StatusMultiSelect.vue'

Investigation

After spending several hours analyzing the source code of the plugin, I identified that this issue was introduced in version 4.1.0 with this commit. Specifically, the problem originates from this line, where the plugin checks for the Vue dependency in the current working directory, rather than in the target package directory.

Proposal

To properly support build execution from different directories, I suggest passing a paths argument to the getPackageInfoSync method. Here's an example:

try {
  hasVue = !!(
    getPackageInfoSync('vue', { paths: [" -> ... <-"] }) ??
    getPackageInfoSync('svelte', { paths: [resolveModule('svelte') || process.cwd()] })
  );
} catch (e) {}

This adjustment should ensure that the plugin correctly resolves dependencies from the appropriate directory.

Reproduction

https://stackblitz.com/~/github.com/sarrooo/vite-plugin-dts-bug

Steps to reproduce

Run: pnpm run build:ui-library with vite-plugin-dts version 4.1.0 check libs/ui-library/dist/index.es.d.ts. Re-try with version 4.0.3.

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 49.02 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.11.1/bin/npm
    pnpm: 9.6.0 - /opt/homebrew/bin/pnpm
  Browsers:
    Chrome: 128.0.6613.120
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-vue: ^5.0.4 => 5.1.3 
    vite: ^5.0.13 => 5.2.9

Validations

@qmhc
Copy link
Owner

qmhc commented Sep 6, 2024

A mistake when doing this feature.

@qmhc qmhc added the bug Something isn't working label Sep 6, 2024
@qmhc qmhc closed this as completed in 0621332 Sep 6, 2024
@sarrooo
Copy link
Author

sarrooo commented Sep 9, 2024

@qmhc the bug is still present

@qmhc
Copy link
Owner

qmhc commented Sep 9, 2024

@qmhc Well, you should run pnpm i -Dw vue, because cwd is root dir, but no Vue dependency in there. Also you can change cwd to the under package root dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants