nx
nx copied to clipboard
Vite executor type checker does not honor buildLibsFromSource flag
Current Behavior
When using the @nx/vite:build executor, the buildLibsFromSource
option allows you to disable rebuilding lib dependencies, and instead just consume the previously built artifacts. The executor implements this by generating a temporary TSConfig file in which all lib paths have been rewritten to point to the dist folder instead. This works good for the build itself, as Vite will use this temporary TSConfig in order to resolve paths.
However, when type checking is enabled, the executor delegates to runTypeCheck
of @nx/js. Unfortunately this no longer takes the temporary TSConfig into account, but instead uses the original one, causing paths to be resolved in the libs folder again.
This is problematic as this means that the TSConfig of the Vite app should be at least as lenient as the TSConfigs of all lib dependencies combined. This breaks incremental builds, as you can no longer use a legacy lib in a more strict Vite app. The problem exists because all dependencies are now typechecked using the compiler options of the vite app, instead of the library's own TSConfig.
Expected Behavior
When buildLibsFromSource
is disabled, the type checker should also use the temporary TSConfig to resolve paths. Usually this will point to the dist folder which typically will contain only .js, .map.js and .d.ts files. Depending on whether skipLibChecks
is enabled, the .d.ts will be type checked.
GitHub Repo
No response
Steps to Reproduce
- Create an nx workspace
- Generate a typescript lib. In the tsconfig.json, add the
noImplicitAny: false
compiler option. In the library, add the following function:
export function thisWillFailTypeCheckingInVite(foo /* no type => implicit any */) {
return "hello";
}
- Generate a vite app which consumes the lib. Make sure the vite app has
noImplicitAny
set to true - Build the vite app.
The library will be built successfully as a dependent project. The noImplicitAny is allowed because of the library TSConfig. The vite app will fail type checking as it does not allow implicit any's. The noImplicitAny is not allowed because of the app TSConfig.
Nx Report
Node : 18.19.0
OS : darwin-x64
yarn : 1.22.19
nx (global) : 18.0.3
nx : 18.0.3
@nx/js : 18.0.3
@nx/jest : 18.0.3
@nx/linter : 18.0.3
@nx/eslint : 18.0.3
@nx/workspace : 18.0.3
@nx/cypress : 18.0.3
@nx/devkit : 18.0.3
@nx/esbuild : 18.0.3
@nx/eslint-plugin : 18.0.3
@nx/node : 18.0.3
@nx/plugin : 18.0.3
@nx/react : 18.0.3
@nrwl/tao : 18.0.3
@nx/vite : 18.0.3
@nx/web : 18.0.3
@nx/webpack : 18.0.3
typescript : 5.3.3
---------------------------------------
Local workspace plugins:
@shared/executors
Failure Logs
No response
Package Manager Version
No response
Operating System
- [X] macOS
- [ ] Linux
- [ ] Windows
- [ ] Other (Please specify)
Additional Information
No response
https://github.com/b-smets/nx/blob/master/packages/vite/src/executors/build/build.impl.ts#L86
A proposed solution could be to let createBuildableTsConfig
return the generated temporary tsConfig path and pass this path here.
If you want I can provide a PR that implements such a solution.
Hi @b-smets :) I think it would be great if you could submit a PR!
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.