Skip to content

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

Closed
volarjs/volar.js
#24
@harveylee

Description

@harveylee

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood reproduction ✨This issue provides a good reproduction, we will be able to investigate it first

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions