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

Vitest won't resolve Path aliases in nx 19.7.2, 19.7.1, 19.7.0 and 19.6.6 #27852

Closed
1 of 4 tasks
jahusa02 opened this issue Sep 10, 2024 · 4 comments · Fixed by #28518
Closed
1 of 4 tasks

Vitest won't resolve Path aliases in nx 19.7.2, 19.7.1, 19.7.0 and 19.6.6 #27852

jahusa02 opened this issue Sep 10, 2024 · 4 comments · Fixed by #28518
Assignees
Labels
scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@jahusa02
Copy link

Current Behavior

Vitest will fail with

Error: Failed to load url @test/other-things/things-things.controller (resolved id: @test/other-things/things-things.controller) in /workspace/vitest/apps/vitest-test/src/things/stuff/bla.mapper.spec.ts. Does the file exist? ❯ loadAndTransform ../../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-BaOMuo4I.js:51847:17

in 19.6.5 it will run fine tho. Please help because that will halt us from updating.

Expected Behavior

Should resolve Path aliases

GitHub Repo

https://github.com/jahusa02/nx-19.7.0-vitest

Steps to Reproduce

  1. run nx test vitest-test

Nx Report

Node           : 20.16.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.10.0

nx (global)        : 19.7.0
nx                 : 19.7.0
@nx/js             : 19.7.0
@nx/jest           : 19.7.0
@nx/eslint         : 19.7.0
@nx/workspace      : 19.7.0
@nx/esbuild        : 19.7.0
@nx/eslint-plugin  : 19.7.0
@nx/node           : 19.7.0
@nrwl/tao          : 19.7.0
@nx/vite           : 19.7.0
@nx/web            : 19.7.0
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
@nx/vite/plugin

Failure Logs

Error: Failed to load url @test/other-things/things-things.controller (resolved id: @test/other-things/things-things.controller) in /workspace/vitest/apps/vitest-test/src/things/stuff/bla.mapper.spec.ts. Does the file exist?
 ❯ loadAndTransform ../../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-BaOMuo4I.js:51847:17

Package Manager Version

[email protected]

Operating System

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

Additional Information

No response

@jahusa02 jahusa02 changed the title Vitest won't resolve Path aliases in nx 19.7.0 and 19.6.6 Vitest won't resolve Path aliases in nx 19.7.2, 19.7.1, 19.7.0 and 19.6.6 Sep 11, 2024
@egonm12
Copy link

egonm12 commented Sep 19, 2024

I have the same problem and suspect it might be related to this change, but I don't have the time to confirm this atm: #27774

@jaysoo jaysoo added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Sep 25, 2024
@0xd0a
Copy link

0xd0a commented Sep 26, 2024

@egonm12 Yes, you are correct.

The culprit is

const { dir, name } = parse(path);

If the file name consists of several segments separated with dots the "parse" will erroneously consider it an extension.

For example

import { a } from "./app.controller";

controller is obviously not an extension.

So #27774 has to be reconsidered.

Also, there are other exotic ways to express a path. For example, vite css-pre-processors page advises to use "path.css?inline", hope that doesn't mess the plugin.

@roshcagra
Copy link

Hi! I'm running into this too while attempting to upgrade to 19.8.2 :(

Is there a known workaround or should I wait for a fix before upgrading?

@dvictory
Copy link

dvictory commented Oct 8, 2024

We also hit this upgrading from 19.6.6

we have in our base tsconfig

"@foo/constants/*": [
        "libs/foo/src/constants/*"
      ]

this fails

import { Bar } from '@foo/constants/bar.constants';

when trying to import file
libs/foo/src/constants/bar.contants.ts

For now we have to stick with 19.6.5

Coly010 pushed a commit to KonstantinKai/nx that referenced this issue Dec 12, 2024
concat `ext` with `filename` for parse in `findFile` function from `nx-tsconfig-paths.plugin` that previously led to an unresolved error for files with dot suffixes e.g.`/dir/file.suffix.ext`

Closes nrwl#27852
Coly010 added a commit that referenced this issue Dec 12, 2024
Use `basename` for retrieving the filename in `findFile` function from
`nx-tsconfig-paths.plugin` that previously led to an unresolved error
for files with dot suffixes e.g.`/dir/file.suffix.ext`

<!-- 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
For files that have the same name but one of them has a suffix, e.g.
```ts
- lib1
  - file.ts
  - file.i18n.ts
- apps
  - app1
    - main.ts
- tsconfig.base.json // with { "paths": { "@lib1/*": ["lib1/*"] }}
```
The resolving process is incorrect because the `import value from
'@lib1/file.i18n'` from `apps/app1/main.ts` every time resolves to
`file.ts,` and the `parse` method from the `node:path` splits away the
suffix from the name.

## Expected Behavior
`import value from '@lib1/file.i18n'` should work correctly if you
import them from another package

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

Fixes #27852

---------

Co-authored-by: Colum Ferry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants