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

Missing typescript checks when using inferred tasks (project Crystal) and vite #27501

Closed
1 of 4 tasks
vtregner-cen29414 opened this issue Aug 19, 2024 · 4 comments · Fixed by #27531 or #27649
Closed
1 of 4 tasks
Assignees
Labels
outdated scope: react Issues related to React support for Nx type: bug

Comments

@vtregner-cen29414
Copy link

Current Behavior

When new monorepo with react application and vite bundler is generated, build task doesn't include Typescript checks. Build is successful even if contains typescript errrors.

Expected Behavior

Build of application with Typescript errors should fail.

GitHub Repo

No response

Steps to Reproduce

Generate repo using npx create-nx-workspace

and with these parameters:

√ Where would you like to create your workspace? · org
√ Which stack do you want to use? · react
√ What framework would you like to use? · none
√ Integrated monorepo, or standalone project? · integrated
√ Application name · org
√ Which bundler would you like to use? · vite
√ Test runner to use for end to end (E2E) tests · none
√ Default stylesheet format · scss
√ Which CI provider would you like to use? · skip
√ Would you like remote caching to make your build faster? · skip

Type some code with typescript error, for example add this line to app.tsx:

const shouldShowError: string = 5;

Build application

nx run org:build

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.10.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 8.9.0

nx                 : 19.6.0
@nx/js             : 19.6.0
@nx/jest           : 19.6.0
@nx/linter         : 19.6.0
@nx/eslint         : 19.6.0
@nx/workspace      : 19.6.0
@nx/devkit         : 19.6.0
@nx/eslint-plugin  : 19.6.0
@nx/react          : 19.6.0
@nrwl/tao          : 19.6.0
@nx/vite           : 19.6.0
@nx/web            : 19.6.0
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

Issue where missing typescript checks was solved in past (prior projet Crystal)
#13954

The Vite discussion points out that TS checks are not part of the Vite build process:
vitejs/vite#12870
https://vitejs.dev/guide/features.html#transpile-only

@FrozenPandaz FrozenPandaz added the scope: react Issues related to React support for Nx label Aug 19, 2024
@Coly010
Copy link
Contributor

Coly010 commented Aug 20, 2024

@vtregner-cen29414 As you've mentioned yourself, TS Checks are not part of the vite build.

Project Crystal's intention is to use the underlying tooling more correctly.

I'll add a typecheck target that gets inferred by the vite plugin, but it'll be a separate target.
You could also do this yourself by adding the following to your targetDefaults in nx.json:

"targetDefaults": {
   "typecheck": {
       "cache": true,
        "inputs": ["^production", "production"].
       "command": "tsc --noEmit -p tsconfig.lib.json",
       "options": {
            cwd: "{projectRoot}"
       }
    }
}

Then in the project.json of any projects you want to ensure typechecking is performed on, add the following:

"targets": {
   "typecheck": {},
   "build": {
       "dependsOn": ["typecheck"]
   }
}

Even if we infer the typecheck target, you'll need to add a dependsOn to the build target if you want it to run before app:build

FrozenPandaz pushed a commit that referenced this issue Aug 21, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Vite intentionally does not run typechecking on projects. They recommend
running `tsc --noEmit` separately.
The `@nx/vite/plugin` could make this easier by adding a `typecheck`
when it detects a `tsconfig` file in the `projectRoot`.
This can then be added to the build pipeline on CI. Or users can add it
to a `dependsOn` for the `build` target if they wish.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
The `@nx/vite/plugin` could make this easier by adding a `typecheck`
when it detects a `tsconfig` file in the `projectRoot`.
This can then be added to the build pipeline on CI. Or users can add it
to a `dependsOn` for the `build` target if they wish.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27501

(cherry picked from commit 6d963fd)
@cwagner22
Copy link

@Coly010 The inferred typecheck PR doesn't load any tsconfig file.
ceff541#diff-e21b84bc7a86a657a55ca6be0f7f8dbe1c2a3ff3475357e0de168fc775c987bbR215

The command tsc --noEmit doesn't do anything if we are using tsconfig.lib.json

@Coly010
Copy link
Contributor

Coly010 commented Aug 27, 2024

Good catch

Coly010 added a commit that referenced this issue Aug 27, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The vite plugin's typecheck target is not using the tsconfig.lib.json
project when running typecheck for libs

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
It should use the correct tsconfig


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27501
FrozenPandaz pushed a commit that referenced this issue Aug 28, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
The vite plugin's typecheck target is not using the tsconfig.lib.json
project when running typecheck for libs

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
It should use the correct tsconfig

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27501

(cherry picked from commit 5648344)
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: react Issues related to React support for Nx type: bug
Projects
None yet
4 participants