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

Built without sensitive environment variables

Name Link
🔨 Latest commit f337ba2
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6920957715224d00077e800f

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

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.

2 participants