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

allow resolution to work when the source file does not exist #16851

Merged
merged 5 commits into from
Jan 31, 2025

Conversation

paperclover
Copy link
Member

@paperclover paperclover commented Jan 28, 2025

Fixes #16705

URL decoding issues

Vite handles percent encoding special characters like / and : in urls, but expects pathToFileURL to encode %2F as %252F (encoding the %). This change has been made in WebKit since i believe all places we create file URLs out of paths should have this, for example import.meta.url in a file named %2F.js (which also matches node)

Resolver changes

Nuxt/Vite uses createRequire("file://...") to facilitate require in files. Some virtual files get a filepath @vue/server-renderer which gets normalized to an absolute path relative to the current working directory (file:///Users/clo/scratch/my-nuxt-app/@vue/server-renderer). This path, given to createRequire, produces a function that cant resolve from node_modules in Bun, but can in Node.js. The bug in Bun is when we walk up for node_modules, we use a directory cache; but the cache is not populated for non-existing directories. The change is to walk up until a cache entry exists, then to use it.

This can be reproduced in the node and bun repls, by replacing the path to your project dir.

require("module").createRequire("file:///Users/clo/scratch/my-nuxt-app/@vue/server-renderer")("vue")

Here is the code path in Node.js that causes this to successfully resolve

@robobun
Copy link

robobun commented Jan 28, 2025

Updated 2:52 AM PT - Jan 30th, 2025

@Jarred-Sumner, your commit 9cf9e00 has 2 failures in Build #10834:


🧪   try this PR locally:

bunx bun-pr 16851

source_dir_to_use = std.fs.path.dirname(source_dir) orelse
return .{ .not_found = {} };
}
};
Copy link
Member Author

@paperclover paperclover Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my worry on this loop is that dirInfoCached does not seem to cache not found entries, which might be worth doing in some places. on the other hand, that type of caching can lead to problems.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does cache not found entries. No need to worry.

@Jarred-Sumner Jarred-Sumner merged commit 322098f into main Jan 31, 2025
66 of 69 checks passed
@Jarred-Sumner Jarred-Sumner deleted the chloe/nuxt branch January 31, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[nuxt] [request error] [unhandled] [500] File URL path must not include encoded / characters
3 participants