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

TS config paths are not correctly resolved when using @nx/vite:test executor #22001

Closed
1 of 4 tasks
getlarge opened this issue Feb 26, 2024 · 6 comments · Fixed by #27118
Closed
1 of 4 tasks

TS config paths are not correctly resolved when using @nx/vite:test executor #22001

getlarge opened this issue Feb 26, 2024 · 6 comments · Fixed by #27118
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@getlarge
Copy link
Contributor

getlarge commented Feb 26, 2024

Current Behavior

I have been migrating a project from Nx 17.1 to 17.3.2 to integrate the nx release flow. When running the generated migration, it bumped the vite and vitest dependencies, which triggered some unexpected issues.

In a nutshell, here's what we found with @BioPhoton :

  • When using custom vite configuration file path(s), vitest fails to resolve the TS config paths when run through the @nx/vite:test executor.
  • When running the tests under the given project's folder with vitest (npx vitest --config=<custom-config-file>), they are running.
  • When overriding the CWD in vitest executor implementation, TS config paths are resolved correctly.

With this patch (in node_modules/@nx/vite/src/executors/test/vitest.impl.js), i suspect that we are forcing vitest to resolve the config file by itself, probably ignoring the other resolvedOptions

// ...
+    resolvedOptions.root = '.';
+    resolvedOptions.config = _path.basename(resolvedOptions.configFile);
+    process.chdir(_path.join(process.cwd(), projectRoot));
    const ctx = await startVitest((_resolvedOptions_mode = resolvedOptions['mode']) != null ? _resolvedOptions_mode : 'test', cliFilters, resolvedOptions);
// ...

Expected Behavior

I expect the custom Vitest config file to be supported since there is an option (config) supported by the executor to declare the configuration file path.

GitHub Repo

https:/getlarge/vitest-issue-repro

Steps to Reproduce

  1. clone the repository
  2. install dependencies (npm i)
  3. run failing tests - npx nx run coffee-maker:test
  4. check the error -> Error: Failed to load url @repro/helpers (resolved id: @repro/helpers) in XXXXX

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 20.11.0
   OS     : darwin-arm64
   npm    : 10.2.4
   
   nx                 : 17.3.2
   @nx/js             : 17.3.2
   @nx/linter         : 17.3.2
   @nx/eslint         : 17.3.2
   @nx/workspace      : 17.3.2
   @nx/devkit         : 17.3.2
   @nx/esbuild        : 17.3.2
   @nx/eslint-plugin  : 17.3.2
   @nrwl/tao          : 17.3.2
   @nx/vite           : 17.3.2
   @nx/web            : 17.3.2
   typescript         : 5.3.3

Failure Logs

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/lib/coffee-maker.spec.ts [ src/lib/coffee-maker.spec.ts ]
Error: Failed to load url @repro/helpers (resolved id: @repro/helpers) in XXXX/vitest-issue-repro/packages/coffee-maker/src/lib/coffee-maker.ts. Does the file exist?
 ❯ loadAndTransform ../../node_modules/vite/dist/node/chunks/dep-jDlpJiMN.js:53601:21

Package Manager Version

10.2.4

Operating System

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

Additional Information

Might be related:

@Coly010
Copy link
Contributor

Coly010 commented May 10, 2024

Thank you for bringing this issue to our attention! I want to assure you that I will take a look as soon as I can. Your patience and understanding in this matter is greatly appreciated.

@huv1k
Copy link

huv1k commented Jul 2, 2024

@Coly010 is there any rough estimate? I know is too much to ask, but just wondering. We wanted update Nx to fix issue with Vitest generator of missing path and now we hit this problem after update 🙈 We really want to move away from Jest, because it blocks us from using ESM :(

@getlarge
Copy link
Contributor Author

getlarge commented Jul 4, 2024

Hi @huv1k, I don't know exactly what blocks you from using ESM with Jest, but I got this setup running in several ESM-based Nx workspace. One of them is open-source, feel free to have a look and send your questions.

@JacobTheEvans
Copy link

Any updates on this issue? We are facing this issue for any nx version past 17

@Coly010
Copy link
Contributor

Coly010 commented Jul 25, 2024

Sorry for the wait everyone, fix is in PR

Coly010 added a commit that referenced this issue Jul 25, 2024
…7118)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https:/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 -->
Plugins were not being loaded by vitest executor when calling
`startVitest` when using a vite config file with a custom name.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Correctly load the plugins found in the resolved config file, regardless
of the config file name


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

Fixes #22001
FrozenPandaz pushed a commit that referenced this issue Jul 30, 2024
…7118)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https:/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 -->
Plugins were not being loaded by vitest executor when calling
`startVitest` when using a vite config file with a custom name.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Correctly load the plugins found in the resolved config file, regardless
of the config file name

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

Fixes #22001

(cherry picked from commit 58cd577)
jaysoo added a commit that referenced this issue Aug 19, 2024
…27514)

This PR ensures that we pass Vite config file to the programmatic
`startTest` API from Vitest. It fixes the issue with plugins not loading
as well as other issues with the config file not being used.

This mainly affects a custom `configFile` option being passed to the
executor. The previous fix to additionally load in `plugins` via
overrides is causing plugins to load twice when the Vite config file is
picked up by Vitest (e.g. #27500).

## Current Behavior
<!-- This is the behavior we have today -->

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

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

Fixes #27500, #22001
FrozenPandaz pushed a commit that referenced this issue Aug 21, 2024
…27514)

This PR ensures that we pass Vite config file to the programmatic
`startTest` API from Vitest. It fixes the issue with plugins not loading
as well as other issues with the config file not being used.

This mainly affects a custom `configFile` option being passed to the
executor. The previous fix to additionally load in `plugins` via
overrides is causing plugins to load twice when the Vite config file is
picked up by Vitest (e.g. #27500).

## Current Behavior
<!-- This is the behavior we have today -->

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

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

Fixes #27500, #22001

(cherry picked from commit 402bae2)
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 Aug 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants