You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the path to your project contains the substring "node_modules", many vite features break. The simplest one to demonstrate is that inline script tags in HTML break.
My reproduction below is the stock vite vanilla blueprint with a single inline script tag added to index.html. All that's needed to reproduce the bug is to name the project "node_modules_bug".
In the specific case of the inline script tag, the failure happens because ensureVersionQuery incorrectly decides that index.html?html-proxy&index=0.js is in node_modules and rewrites it to index.html?v=af416d6b&html-proxy&index=0.js, which then fails to match the regex in html-inline-proxy, because that regex only works when html-proxy is the first search param in the URL.
At a minimum, isInNodeModules should probably require path separators on both sides of the node_modules string. This would fix my specific reproduction, but would still leave people broken who happen to have a project root with an ancestor directory named "node_modules" (which is definitely a thing sometimes when dealing with legacy codebases).
A complete fix would make isInNodeModules aware of the configured root, because whether or not a given path comes into your project via node_modules is ultimately a question relative to that root:
Given:
root=/path/to/node_modules/your-project
Then:
inNodeModules("/path/to/node_modules/your-project/x", root) -> false because x is clearly in our configured root
inNodeModules("/path/to/node_modules/your-project/node_modules/y", root) -> true because we left the configured root "inward"
inNodeModules("/path/to/node_modules/z", root) -> true because we left the configured root "outward"
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
If the path to your project contains the substring "node_modules", many vite features break. The simplest one to demonstrate is that inline script tags in HTML break.
My reproduction below is the stock vite vanilla blueprint with a single inline script tag added to index.html. All that's needed to reproduce the bug is to name the project "node_modules_bug".
In the specific case of the inline script tag, the failure happens because ensureVersionQuery incorrectly decides that
index.html?html-proxy&index=0.js
is in node_modules and rewrites it toindex.html?v=af416d6b&html-proxy&index=0.js
, which then fails to match the regex in html-inline-proxy, because that regex only works whenhtml-proxy
is the first search param in the URL.At a minimum,
isInNodeModules
should probably require path separators on both sides of thenode_modules
string. This would fix my specific reproduction, but would still leave people broken who happen to have a project root with an ancestor directory named "node_modules" (which is definitely a thing sometimes when dealing with legacy codebases).A complete fix would make
isInNodeModules
aware of the configured root, because whether or not a given path comes into your project via node_modules is ultimately a question relative to that root:Reproduction
https://github.com/ef4/node_modules_bug
Steps to reproduce
System Info
System: OS: macOS 14.5 CPU: (10) arm64 Apple M1 Max Memory: 4.20 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.14.0 - /usr/local/bin/node npm: 10.7.0 - /usr/local/bin/npm pnpm: 8.15.8 - /usr/local/bin/pnpm Watchman: 2023.02.13.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 125.0.6422.142 Safari: 17.5 npmPackages: vite: ^5.2.0 => 5.3.0
Used Package Manager
pnpm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: