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

Can't use project references without building depended project first #2296

Closed
harveylee opened this issue Jan 9, 2023 · 7 comments · Fixed by volarjs/volar.js#24
Closed
Labels
enhancement New feature or request good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@harveylee
Copy link

We want to import API types from the api project into the app project in a monorepos without having to build the .d.ts files. We use project references so that path mappings in the api project can be resolved when imported into the app project. Without using project references (in app) the types are imported as any.

When using Volar in takeover mode, we get:
Output file '/fleetseer/packages/api/lib/index.d.ts' has not been built from source file '/fleetseer/packages/api/src/index.ts'. in our app project, when importing @fleetseer/api.

However, this use case appears to be supported by the built-in VS Code TypeScript support. If we turn on TypeScript and JavaScript Language Features in VS Code, the types are correctly resolved by the built-in thing for *.ts files (but no change for *.vue files, as expected).

This may be related / a duplicate of #1815

Activating the workspace setting "Volar > Vueserver: No Project References" makes the "Output file has not been built" error go away, however the path mappings in api don't resolve correctly.

  • One workaround here without project references is to use relative paths in api (e.g. ../../../../my-api-thing.ts in some cases) which is quite painful

Notes:

  • Using Volar 1.0.24 in VS Code in takeover mode
  • Using Typescript project references in a PNPM monorepos
  • @fleetseer/api is a added as a pnpm workspace dependency (i.e. in package.json: "@fleetseer/api": "workspace:*") to the app project.
  • The api project is a composite: true project referred to by the app project
  • This error appears for both *.ts and *.vue files in the app project
  • In api we have a path mapping in tsconfig.json to map "~/*": ["./*"] with "baseUrl": "./src"

Also both vite (using vite-tsconfig-paths) and esbuild (using @esbuild-plugins/tsconfig-paths) seem to be able to resolve the ~/* alias correctly on build, with the help of the plugins - perhaps there's a similar plugin for Volar?

In the end, I think we either:
A. Resolve the reason why the project references don't resolve the same way as the built-in TS services; or
B. Find a way to get the path mapping (e.g. ~/*) in depended projects (i.e. api in our case) to work without using project references, as a workaround (perhaps using something like a tsconfig-paths plugin?)

Versions

  • Typescript 4.9.4
  • Volar 1.0.24
  • Vue 3.2.45
  • VS Code 1.74.2
  • Windows 11 (WSL Debian)
@everhardt
Copy link

I ran into the same thing a while back and also have not been able to fix it yet, see johnsoncodehk/volar-starter#7

@johnsoncodehk
Copy link
Member

Can you try enable noProjectReferences?

@everhardt
Copy link

Yes, awesome, that works for me! Should that maybe also be added to the volar-starter repo? See johnsoncodehk/volar-starter#7

@harveylee
Copy link
Author

noProjectReferences doesn't work for me.

If I enable noProjectReferences, path aliases don't work in the dependency.

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Jan 23, 2023

If you can provide minimal reproduction, I will be able to narrow down the problem.

@everhardt volar-starter is not a template for production, it is better to work with create-vue instead.

@harveylee
Copy link
Author

I created a bare-bones pnpm monorepo based on pnpm create vite here: https://github.com/harveylee/volar-path-alias

A description of the setup is in the README along with some steps to follow to reproduce the various states and error messages. Hopefully that helps.

@blake-newman
Copy link
Member

Should be resolved with: volarjs/volar.js#24

@johnsoncodehk johnsoncodehk added enhancement New feature or request good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed need info labels Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants