GeezerVison is showing github.com — File URLs in module.noParse, resolve.restrictions, and stats.context are not converted to filesystem paths · Issue #22057 · webpack/webpack
File URLs in module.noParse, resolve.restrictions, and stats.context are not converted to filesystem paths #22057Labels area: configOptions, defaults, validation (lib/config, schemas/)area: resolvingModule resolution, aliases, exports/imports mapsregressionWorked in a previous release; pair with the Affected version field DescriptionHave you used AI?
Yes
Which part of webpack is affected?
config (options, defaults, validation)
Bug Description
In #22012 / commit 3a69d296, webpack updated schema-utils to accept file:// URLs wherever an option takes an absolute path (via "absolutePath": true), and added fileUrlToPath conversions during options normalization in lib/config/normalization.js for options like context, output.path, recordsInputPath, recordsOutputPath, cacheDirectory, cacheLocation, snapshot.managedPaths, etc.
However, several other options that take absolute paths per schemas/WebpackOptions.json were omitted from normalization in lib/config/normalization.js:
-
module.noParse (definitions.NoParse): Accepts string (or string[]) with "absolutePath": true. When configured as a file:// URL (e.g. from import.meta.resolve() or new URL()), schema validation passes, but normalization.js does not convert it to a filesystem path. In lib/NormalModule.js:1553, applyNoParseRule(rule, content) checks content.startsWith(rule). Since content is a filesystem path (/abs/path/to/mod.js) and rule is a file URL (file:///abs/path/to/mod.js), startsWith always returns false. Webpack silently parses the module anyway, completely defeating noParse.
-
resolve.restrictions & resolveLoader.restrictions (definitions.ResolveOptions.properties.restrictions): Array of strings/RegExps where strings have "absolutePath": true. Schema validation accepts file:// URLs, but they are passed directly to enhanced-resolve without conversion, causing resolution failure for all allowed files (Module not found: Error: Can't resolve ...).
-
stats.context (definitions.StatsOptions.properties.context): Has "absolutePath": true. Schema validation accepts a file:// URL, but without normalization it is passed to RequestShortener, which breaks relative path computation in contextify, producing malformed paths like ../../../../../../path/to/file.js.
Link to Minimal Reproduction and steps to reproduce
Minimal Node reproduction script:
const webpack = require("webpack");
const path = require("path");
const fs = require("fs");
const { pathToFileURL } = require("url");
const testFile = path.resolve("./temp-noparse.js");
// If noParse works, this file is not parsed and the missing require is ignored.
// If noParse fails, webpack parses it and throws ModuleNotFoundError.
fs.writeFileSync(testFile, 'require("non-existent-module");\n');
const fileUrl = pathToFileURL(testFile).href;
webpack({
mode: "development",
entry: testFile,
output: { path: path.resolve("./dist-test") },
module: {
noParse: fileUrl // file URL accepted by schema validation
}
}, (err, stats) => {
if (stats && stats.hasErrors()) {
console.error("FAILED - module was parsed despite noParse:", stats.compilation.errors[0].message);
} else {
console.log("SUCCESS - module was not parsed");
}
fs.unlinkSync(testFile);
});
Steps:
- Run the script above with webpack
main (post-feat: accept file URLs where an option takes an absolute path #22012).
- Schema validation succeeds without error.
- Build fails with
Module not found: Error: Can't resolve 'non-existent-module' because NormalModule.applyNoParseRule compares content.startsWith("file:///...") against /abs/path/to/temp-noparse.js.
- If replaced with
noParse: testFile (plain filesystem path), the build succeeds without error.
Expected Behavior
Options taking absolute paths that accept file:// URLs should be converted to filesystem paths during options normalization in lib/config/normalization.js:
module.noParse: String URLs (scalar or in arrays) should be converted with fileUrlToPath.
resolve.restrictions and resolveLoader.restrictions: String URLs should be converted with fileUrlsToPaths.
stats.context: String URLs should be converted with optionalFileUrlToPath.
Actual Behavior
module.noParse with a file URL silently fails to match and modules are parsed anyway.
resolve.restrictions with a file URL fails resolution for allowed paths.
stats.context with a file URL causes RequestShortener / contextify to output broken relative paths.
Environment
System:
OS: macOS 26.6.2
CPU: (8) arm64 Apple M3
Binaries:
Node: 22.23.1
npm: 10.9.8
yarn: 1.22.22
Packages:
webpack: 5.110.3 (main)
Is this a regression?
Yes (please specify version below)
Last Working Version
Introduced with #22012 / commit 3a69d296
Additional Context
In lib/config/normalization.js, module.noParse is currently passed through without conversion:
Similarly, resolve.restrictions and resolveLoader.restrictions are not passed through fileUrlsToPaths, and stats.context is not passed through optionalFileUrlToPath. ActivityPcmhacker-piro commented on Sep 12, 2026 ContributorAuthor More actions I've raised a PR to fix this: #22066. Could you please take a look when you get a chance?
MetadataMetadataarea: configOptions, defaults, validation (lib/config, schemas/)area: resolvingModule resolution, aliases, exports/imports mapsregressionWorked in a previous release; pair with the Affected version field DevelopmentNo branches or pull requestsIssue actions
|