Skip to content

Support absolute paths with file:// protocol prefix #209

Closed

Description

@laymonage

Feature Proposal

It would be great if Webpack allows paths prefixed with file:// protocol when checking for absolute paths.

Feature Use Case

I'm migrating my config from CommonJS to ESM.

The config has require.resolve() that we use for generating the test regex for the loader config of certain packages. An ESM equivalent is import.meta.resolve(), but it returns the absolute path using the file:// protocol prefix. This results in the following error:

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[7] should be one of these:
   ["..." | false | 0 | "" | null | undefined | object { assert?, compiler?, dependency?, descriptionData?, enforce?, exclude?, extractSourceMap?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use?, with? }, ...]
   -> A rule.
   Details:
    * configuration.module.rules[3].test: The provided value "file:///wagtail/node_modules/focus-trap-react/dist/focus-trap-react.js" is not an absolute path!
    * configuration.module.rules[4].test: The provided value "file:///wagtail/node_modules/react/index.js" is not an absolute path!
    * configuration.module.rules[5].test: The provided value "file:///wagtail/node_modules/react-dom/index.js" is not an absolute path!
    * configuration.module.rules[6].test: The provided value "file:///wagtail/node_modules/react-transition-group/CSSTransitionGroup" is not an absolute path!
    * configuration.module.rules[7].test: The provided value "file:///wagtail/node_modules/draft-js/lib/Draft.js" is not an absolute path!

A workaround is to strip the file:// prefix, e.g. using new URL().pathname (or a simple string replace would do):

const url = import.meta.resolve(name);
const test = new URL(url).pathname;

I don't see a reason why the file:// prefix would be problematic in this case, so I think it would be great if Webpack supports it out-of-the-box.

Additional Context

I think this can be done by updating the following regex:

// ?:[A-Za-z]:\\ - Windows absolute path
// \\\\ - Windows network absolute path
// \/ - Unix-like OS absolute path
const isCorrectAbsolutePath =
schema === /^(?:[A-Za-z]:(\\|\/)|\\\\|\/)/.test(data);

Happy to submit a PR for it, but I'm not sure if that's the only thing needs updating to support this.

Thanks!

Activity

  1. alexander-akait commented on Feb 3, 2026

    @alexander-akait
    Member

    PR welcome, ideally we need to add a test cases in webpack to ensure we support in most of places file:, but for resolver we support it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions