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

Vite resolves file from cwd instead of node module if the names are identical #15500

Closed
7 tasks done
sheremet-va opened this issue Jan 3, 2024 · 3 comments
Closed
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@sheremet-va
Copy link
Member

Describe the bug

This is based on vitest-dev/vitest#4860

I was able to reduce reproduction to a few lines:

import { createServer } from 'vite';
const s = await createServer();
console.log(await s.pluginContainer.resolveId('tsoa'));
s.close();

The expectation is that tsoa will be resolved to the package in node modules, not to tsoa.json file in the root of the project.

Reproduction

https://stackblitz.com/edit/vitejs-vite-pivsa8?file=vite.mjs,package.json

Steps to reproduce

node vite.mjs

System Info

Stackblitz

Used Package Manager

npm

Logs

No response

Validations

@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) labels Jan 3, 2024
Copy link

stackblitz bot commented Jan 3, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@XiSenao
Copy link
Collaborator

XiSenao commented Jan 4, 2024

If the importer is not specified when using the pluginContainer.resolveId hook, Vite will default to treating the importer as the entry module (index.html).

async resolveId(rawId, importer = join(root, 'index.html'), options) {

if (
id[0] === '.' ||
((preferRelative || importer?.endsWith('.html')) &&
startsWithWordCharRE.test(id))
) {

Using it in the following way may meet your expectations.

await s.pluginContainer.resolveId('tsoa’, null)

refs: #8122 #8808

@sheremet-va
Copy link
Member Author

If the importer is not specified when using the pluginContainer.resolveId hook, Vite will default to treating the importer as the entry module (index.html).

Thank you for investigating. I can confirm that passing down the importer correctly resolves the path.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
@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.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants