Repository navigation
Description
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:
schema-utils/src/keywords/absolutePath.js
Lines 73 to 77 in 3b103ae
| // ?:[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!
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
alexander-akait commentedon Feb 3, 2026
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 itfeat: accept file URLs where an option takes an absolute path
feat: accept file URLs where an option takes an absolute path
feat: accept file URLs where an option takes an absolute path (#22012)