GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #22057

New issue
Copy link
New issue
Copy link
Closed
Closed
File URLs in module.noParse, resolve.restrictions, and stats.context are not converted to filesystem paths#22057
Copy link
Labels
area: configOptions, defaults, validation (lib/config, schemas/)area: resolvingModule resolution, aliases, exports/imports mapsregressionWorked in a previous release; pair with the Affected version field

Description

@Pcmhacker-piro
Pcmhacker-piro
opened on Sep 11, 2026
Issue body actions

Have 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:

  1. 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.

  2. 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 ...).

  3. 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:

  1. Run the script above with webpack main (post-feat: accept file URLs where an option takes an absolute path #22012).
  2. Schema validation succeeds without error.
  3. 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.
  4. 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:

noParse: module.noParse,

Similarly, resolve.restrictions and resolveLoader.restrictions are not passed through fileUrlsToPaths, and stats.context is not passed through optionalFileUrlToPath.

Activity

  1. coderabbitai
    added
    area: configOptions, defaults, validation (lib/config, schemas/)
    area: resolvingModule resolution, aliases, exports/imports maps
    regressionWorked in a previous release; pair with the Affected version field
    on Sep 11, 2026
  2. Pcmhacker-piro commented on Sep 12, 2026

    @Pcmhacker-piro
    Pcmhacker-piro
    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?

  3. alexander-akait
    closed this as completedon Sep 12, 2026
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

    area: configOptions, defaults, validation (lib/config, schemas/)area: resolvingModule resolution, aliases, exports/imports mapsregressionWorked in a previous release; pair with the Affected version field

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.