Skip to content

feat: add import.meta.resolve support for bundle config loader#20515

Closed
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-1ad05549-fe59-4c66-8bc6-df4e67aaafa6
Closed

feat: add import.meta.resolve support for bundle config loader#20515
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-1ad05549-fe59-4c66-8bc6-df4e67aaafa6

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 31, 2025

This PR adds import.meta.resolve support to Vite's bundle config loader, applying the same logic from #20260 but for configuration files during bundling.

Problem

Currently, when using import.meta.resolve in Vite configuration files, it fails with an error because the config bundling process doesn't provide a working implementation:

// vite.config.mjs
export default {
  define: {
    RESOLVED_PATH: import.meta.resolve('./some-module'), // ❌ Fails
  },
}

This occurs because the bundleConfigFile function uses esbuild to bundle config files, and while it defines replacements for import.meta.url, import.meta.dirname, etc., it was missing import.meta.resolve.

Solution

The implementation follows the same pattern as other import.meta.* properties already supported in the config bundler:

  1. Added import.meta.resolve to esbuild's define object - Maps import.meta.resolve calls to an injected resolver function
  2. Implemented resolver function injection - Creates a working resolver that:
    • Attempts to use Node.js's native import.meta.resolve when available
    • Falls back to a custom implementation for relative paths with proper file extension resolution
    • Handles both .js, .mjs, .cjs, .ts, .mts, and .cts extensions
  3. Added proper cleanup - Ensures the global resolver is cleaned up after config loading

Usage

Now you can use import.meta.resolve in your Vite config files:

// vite.config.mjs
export default {
  define: {
    HELPER_MODULE: import.meta.resolve('./utils/helper.js'), // ✅ Works
    BASE_URL: import.meta.url,
  },
}

Testing

Added comprehensive test cases covering:

  • Basic import.meta.resolve usage with relative paths
  • File extension resolution (with and without explicit extensions)
  • Advanced scenarios with multiple resolve calls
  • Proper integration with the existing config loading infrastructure

Closes #[issue-number] (if applicable)

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • vite.dev
    • Triggering command: /home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1181/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-6XKFRu --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1181/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-JRQzep --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • workers.cloudflare.com
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 2) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 31, 2025 17:47
… config loader

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI changed the title [WIP] Add import.meta.resolve support for the bundle config loader. The same logic from @vitejs/vite/pull/20260 can be used. feat: add import.meta.resolve support for bundle config loader Jul 31, 2025
Copilot AI requested a review from sapphi-red July 31, 2025 17:56
Copy link
Copy Markdown

@Samiullahstanikzai Samiullahstanikzai left a comment

Choose a reason for hiding this comment

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

need clean and clear :)

@sapphi-red
Copy link
Copy Markdown
Member

=> #20962

@sapphi-red sapphi-red closed this Oct 19, 2025
@bluwy bluwy deleted the copilot/fix-1ad05549-fe59-4c66-8bc6-df4e67aaafa6 branch November 18, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants