Skip to content

Rollup adapter is not resolving virtual modules correctly in windows environments #2078

@giamir

Description

@giamir

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:

  • injectedFilePath evaluates to false
  • path.isAbsolute(source) evaluates to false
  • whatwgUrl.parseURL(source) evaluates to an object (C:\Users\etc is considered a valid url by the whatwgUrl package)

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', '')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions