Visitar URL original
fix(config): normalize file URLs for options taking absolute paths by Pcmhacker-piro · Pull Request #22059 · webpack/webpack · GitHub
Skip to content

fix(config): normalize file URLs for options taking absolute paths - #22059

Closed
Pcmhacker-piro wants to merge 1 commit into
webpack:mainfrom
Pcmhacker-piro:fix/file-url-normalization
Closed

Pcmhacker-piro wants to merge 1 commit into
webpack:mainfrom
Pcmhacker-piro:fix/file-url-normalization

Conversation

@Pcmhacker-piro

@Pcmhacker-piro Pcmhacker-piro commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In #22012 / commit 3a69d29, webpack added support for file:// URLs wherever options take an absolute path, converting them during options normalization in lib/config/normalization.js for options like context, output.path, snapshot.managedPaths, cacheDirectory, etc.

However, several other options that take "absolutePath": true per schemas/WebpackOptions.json were omitted from normalization:

  • module.noParse: NormalModule.applyNoParseRule compares content.startsWith(rule). Since content is a filesystem path and rule remained a file:// URL, they never matched, causing modules to be parsed unexpectedly.
  • resolve.restrictions & resolveLoader.restrictions: passed directly to enhanced-resolve as file:// URLs, causing resolution failures for allowed paths.
  • stats.context: passed to RequestShortener / contextify without normalization, causing broken relative paths.
  • dotenv.dir & experiments.buildHttp: passed to path utilities expecting filesystem paths.

This PR normalizes file URLs to filesystem paths for these options in lib/config/normalization.js.

Fixes #22057.

What kind of change does this PR introduce?

bugfix

Did you add tests for your changes?

Yes:

  • Unit tests in test/Normalization.unittest.js covering normalization of module.noParse, resolve.restrictions, resolveLoader.restrictions, stats.context, dotenv.dir, and experiments.buildHttp.
  • Integration config test in test/configCases/no-parse/file-url/ (gated with supportsFileUrlPaths() matching test/configCases/rule-set/file-url-condition/).

Does this PR introduce a breaking change?

No. Non-file-URL values, RegExps, and functions pass through unchanged.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Yes

Summary by CodeRabbit

  • New Features

    • File URLs are now normalized to filesystem paths across more configuration options, including module parsing, resolution restrictions, statistics context, dotenv settings, and HTTP build settings.
    • noParse supports file URLs, allowing selected modules to remain unparsed while other modules continue to be processed normally.
  • Bug Fixes

    • Improved consistency when configuration values use file URLs alongside regular paths and expressions.

Commit 3a69d29 updated the schema validator to accept file URLs
wherever an option takes an absolute path, and normalized file URLs
for options like context, output.path, cacheDirectory, etc.

However, several other options accepting absolute paths per schema were
omitted from normalization in lib/config/normalization.js:
- module.noParse: NormalModule checks content.startsWith(rule) which
  silently failed to match filesystem paths against file URLs.
- resolve.restrictions and resolveLoader.restrictions: passed to
  enhanced-resolve as file URLs, causing resolution errors for allowed paths.
- stats.context: passed to RequestShortener / contextify, causing broken
  relative paths.
- dotenv.dir and experiments.buildHttp: passed to path join utilities
  expecting filesystem paths.

Now all of these options convert file URLs to filesystem paths during
options normalization.

Closes webpack#22057.
@github-actions github-actions Bot added the area: config Options, defaults, validation (lib/config, schemas/) label Sep 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi there! This PR was automatically flagged and closed by our quality checks.

If you believe this was a mistake, please review our contributing guidelines
and leave a comment explaining why this is a mistake.

@github-actions github-actions Bot closed this Sep 11, 2026
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: ac567add-af7e-405b-b53f-8292e9fb1dad

📥 Commits

Reviewing files that changed from the base of the PR and between 3a69d29 and a3736e5.

📒 Files selected for processing (10)
  • .changeset/007-file-url-normalization.md
  • lib/config/normalization.js
  • test/Normalization.unittest.js
  • test/configCases/no-parse/file-url/dep.js
  • test/configCases/no-parse/file-url/index.js
  • test/configCases/no-parse/file-url/not-parsed-a.js
  • test/configCases/no-parse/file-url/not-parsed-b.js
  • test/configCases/no-parse/file-url/parsed.js
  • test/configCases/no-parse/file-url/test.filter.js
  • test/configCases/no-parse/file-url/webpack.config.js

📝 Walkthrough

Walkthrough

Webpack now converts file URLs to filesystem paths for additional configuration options. Unit tests cover conversion and preservation of existing values. A new configuration case verifies file URL support for module.noParse.

Changes

File URL normalization

Layer / File(s) Summary
Configuration normalization
lib/config/normalization.js, .changeset/007-file-url-normalization.md
Normalizes file URLs in module.noParse, dotenv.dir, HTTP build locations, resolver restrictions, and stats.context.
Normalization tests
test/Normalization.unittest.js
Verifies file URL conversion and preserves plain paths and regular expressions.
noParse file URL case
test/configCases/no-parse/file-url/*
Verifies that modules matched by file URLs are not parsed and that other modules remain parsed.

Change: Bug fix · Severity of issue fixed: Medium


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Pcmhacker-piro

Copy link
Copy Markdown
Contributor Author

Superseded by #22066.

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

Labels

area: config Options, defaults, validation (lib/config, schemas/)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File URLs in module.noParse, resolve.restrictions, and stats.context are not converted to filesystem paths

1 participant