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 report] importing dependencies by fs paths results in two different copies of the same module #2503

Closed
3 tasks done
meteorlxy opened this issue Mar 13, 2021 · 0 comments · Fixed by #2848 or #9848
Closed
3 tasks done
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@meteorlxy
Copy link
Contributor

meteorlxy commented Mar 13, 2021

⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.

Describe the bug

Importing dependencies in node_modules by fs paths will cause unexpected behavior, because we only do version hash injection for bare imports:

const versionHash = server._optimizeDepsMetadata?.browserHash
if (versionHash && isJsType) {
resolved = injectQuery(resolved, `v=${versionHash}`)
}

Reproduction

Reproduce repo: https://github.com/meteorlxy/repro-vite-2503

  1. Having a foo module:
// node_modules/foo/index.js
export default Symbol()
  1. Having a bar module that depends on foo module:
// node_modules/bar/index.js
import fooSymbol from 'foo'

export default fooSymbol
  1. Importing foo and bar via fs paths:
// index.js
import fooSymbol from './node_modules/foo'
import barSymbol from './node_modules/bar'

console.log(fooSymbol === barSymbol) // false

Explanation

  • No version hash will be injected in index.js because there is no bare import.
  • Version hash will be injected in node_modules/bar/index.js, because it uses bare import for foo module.

System Info

  • vite version: 2.0.5
  • Operating System: Linux
  • Node version: 12.16.1
  • Package manager (npm/yarn/pnpm) and version: npm 7.6.2
meteorlxy added a commit to vuepress/core that referenced this issue Mar 14, 2021
@patak-dev patak-dev added bug p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels Mar 31, 2021
patak-dev added a commit that referenced this issue May 4, 2021
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
fi3ework pushed a commit to fi3ework/vite that referenced this issue May 22, 2021
vitejs#2848)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
@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.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
2 participants