-
-
Notifications
You must be signed in to change notification settings - Fork 320
Description
I have bumped into an issue where the rollupAdapter is not resolving virtual modules due to the presence of a conventional null byte which messes up with few guard conditions and tricks the adapter to believe that the import specifier (source in the snippet below) is a relative url.
const injectedFilePath = path.normalize(source).startsWith(rootDir);
if (!injectedFilePath && !path.isAbsolute(source) && whatwgUrl.parseURL(source) != null) {
// don't resolve relative and valid urls
return source;
}In the above snippet of code when the source is something like "\x00C:\\Users\\giamir\\Code\\MyRepo\\node_modules\\@testing-library\\dom\\dist\\helpers.js?commonjs-exports" then:
injectedFilePathevaluates tofalsepath.isAbsolute(source)evaluates tofalsewhatwgUrl.parseURL(source)evaluates to anobject(C:\Users\etcis considered a valid url by thewhatwgUrlpackage)
This prevent the virtual module from being resolved correctly by the dev server (instead the server try to access a file directly from disk C:\\Users\\giamir\\Code\\MyRepo\\node_modules\\@testing-library\\dom\\dist\\helpers.js?commonjs-exports)
The only reason why this is not happening in POSIX systems is beacuse whatwgUrl.parseURL(source) evaluate to null (/Users/etc is not considered a valid url by the whatwgUrl package).
I am planning to open a small PR which performs the absolute path check in the import specifier (source) stripped out of the null byte prefix:
path.isAbsolute(source.replace('\0', '')