Skip to content

Conversation

@MIreland
Copy link

Description

This PR fixes an issue where import.meta.url was unconditionally replaced by the local file path during the build, causing file:/// URLs to appear in web builds.

Fix

Modified ImportMetaPlugin to check if the target environment supports document. If it does (web target), import.meta.url is preserved in the output.

Verification

Added a new test case tests/rspack-test/configCases/parsing/import-meta-url-web which asserts that import.meta.url is not replaced by a file:// URL when targeting web.

Copilot AI review requested due to automatic review settings November 21, 2025 16:38
@netlify
Copy link

netlify bot commented Nov 21, 2025

Deploy Preview for rspack ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 396aa66
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/692bc51be15a7b000865f7ab
😎 Deploy Preview https://deploy-preview-12266--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@CLAassistant
Copy link

CLAassistant commented Nov 21, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Nov 21, 2025
Copilot finished reviewing on behalf of MIreland November 21, 2025 16:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where import.meta.url was incorrectly replaced with a file:// URL during the build process for web targets. The fix ensures that when targeting web environments (where document is supported), import.meta.url is preserved in the output, allowing the browser to resolve it to the actual script URL at runtime.

Key Changes:

  • Modified ImportMetaPlugin to check target environment capabilities before replacing import.meta.url
  • Added test case to verify import.meta.url preservation in web targets

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
crates/rspack_plugin_javascript/src/parser_plugin/import_meta_plugin.rs Updated evaluate_identifier and member methods to conditionally preserve import.meta.url based on whether the target supports document
tests/rspack-test/configCases/parsing/import-meta-url-web/rspack.config.js Test configuration targeting web environment
tests/rspack-test/configCases/parsing/import-meta-url-web/index.js Test assertion verifying import.meta.url is not a file path in web builds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

start,
end,
))
if parser.compiler_options.output.environment.supports_document() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script must be an ES module to use import.meta.url. We could not use supports_document() to determine this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed an update

The script must be an ES module to use import.meta.url. We cannot use supports_document() to determine this. This change adds a check for parser.is_esm before handling import.meta.url in both evaluate_identifier and member methods.
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 30, 2025

CodSpeed Performance Report

Merging #12266 will not alter performance

Comparing MIreland:fix/import-meta-url-web (396aa66) with main (5838590)1

Summary

✅ 17 untouched

Footnotes

  1. No successful run was found on main (ece652e) during the generation of this report, so 5838590 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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

Labels

release: bug fix release: bug related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants