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 imports file from cwd directy instead of node module if the names are identical #4860

Closed
6 tasks done
ValentinGurkov opened this issue Jan 3, 2024 · 4 comments
Closed
6 tasks done

Comments

@ValentinGurkov
Copy link

ValentinGurkov commented Jan 3, 2024

Describe the bug

In the first example below you will see a test file that imports the tsoa library and console.logs everything inside it.
Due to a tsoa.json existing at the root, the file is read instead and its' contents logged into the console instead of the package's contents.

In the second example tsoa.json is renamed to tsoa.config.json. Since the names are no longer identical, the package contents are logged instead of JSON files.

#2788 already reported something similar but was closed by the author.

For what it's worth, I'm migrating from jest and the same scenario is not reproducible there.

Reproduction

With identical name

  1. Visit https://stackblitz.com/edit/vitejs-vite-tj9sr8
  2. Execute npm run test in the terminal
  3. Observe the "tsoa" console log - it is not outputting the library, so the import does not ask expected.

When the names are not identical

  1. Visit https://stackblitz.com/edit/vitejs-vite-zhvhps
  2. Execute npm run test in the terminal
  3. Observe the "tsoa" console log - it imports the library as expected.

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 5.23 GB / 31.21 GB
  Binaries:
    Node: 20.10.0 - C:\program files\nodejs\node.EXE
    Yarn: 1.22.21 - C:\program files\nodejs\yarn.CMD
    npm: 10.2.3 - C:\program files\nodejs\npm.CMD
    pnpm: 8.14.0 - C:\program files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (120.0.2210.91)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitest/coverage-v8: ^1.1.1 => 1.1.1
    vitest: ^1.1.1 => 1.1.1

Used Package Manager

pnpm

Validations

@ValentinGurkov ValentinGurkov changed the title vitest imports file from cwd directy instead of node module if the names are identical. vitest imports file from cwd directy instead of node module if the names are identical Jan 3, 2024
@sheremet-va
Copy link
Member

This is an issue with how Vite resolves modules. I opened an issue at vitejs/vite#15500

@sheremet-va
Copy link
Member

After more investigation, I didn't find any errors: tsoa is correctly resolved - https://stackblitz.com/edit/vitejs-vite-tgveho?file=src%2Fmain.js,vitest.config.js

It prints:

tsoa {
  Deprecated: [Getter],
  Example: [Getter],
  Body: [Getter],
  BodyProp: [Getter],
...

Copy link

github-actions bot commented Jan 4, 2024

Hello @ValentinGurkov. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@ValentinGurkov
Copy link
Author

After more investigation, I didn't find any errors: tsoa is correctly resolved - https://stackblitz.com/edit/vitejs-vite-tgveho?file=src%2Fmain.js,vitest.config.js

It prints:

tsoa {
  Deprecated: [Getter],
  Example: [Getter],
  Body: [Getter],
  BodyProp: [Getter],
...

I've also run this again and the issue did not reproduce.
Thanks for spending some of your time on this but I will close the issue and see if I'll be able to reproduce this again in a small repo.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants