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

Bug when rewriting relative import in un-optimized node_modules #204

Closed
csr632 opened this issue May 20, 2020 · 2 comments
Closed

Bug when rewriting relative import in un-optimized node_modules #204

csr632 opened this issue May 20, 2020 · 2 comments

Comments

@csr632
Copy link
Member

csr632 commented May 20, 2020

Do NOT ignore this template or your issue will have a very high chance to be closed without comment.

Describe the bug

In this line, the ctx.path may be a direcory.
https://github.com/vuejs/vite/blob/6683bb8fb819c6f4935b40f25c2a377037e5ec7d/src/node/server/serverPluginModuleRewrite.ts#L129

But when you resolve relative import, you treat it as a file path.
https://github.com/vuejs/vite/blob/49a44b648f263ff058f730913ea1ee6c62e3cd2d/src/node/utils/pathUtils.ts#L16

For example, if /dir/index.js have import './utils', and browser request for /dir, vite will try to find utils from /utils instead of /dir/utils

@yyx990803
Copy link
Member

yyx990803 commented May 20, 2020

importer is always the resolved full path with filename because we pre-resolve the imports (i.e. the file with import './dir' will already have been rewritten to import './dir/index.js').

Please make sure to only open issues when you reproduce it.

@csr632
Copy link
Member Author

csr632 commented May 21, 2020

@yyx990803

Here is a minimal reproduce:
https://github.com/csr632/test-vite/tree/wrong-resolve

It happends when I config optimizeDeps.auto = false.
This bug only happends when rewriting import in un-optimized node_modules.

@csr632 csr632 changed the title relative import is incorrectly resolved Bug when rewriting relative import in un-optimized node_modules May 21, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
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