Skip to content

new URL(url, import.meta.url) does not work when query parameters are present #13017

@benmccann

Description

@benmccann

Describe the bug

The following does not work because of the query parameter:

const demo = (x) => new URL(`/sample/${x}/example.jpg?abc`, import.meta.url).href

If you remove ?abc then it works again.

Here are the docs for this feature: https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url

And the code for the feature: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/assetImportMetaUrl.ts

Query parameters are needed to support vite-imagetools

#11157 is potentially related, but it's unclear if it's the same issue

Reproduction

https://github.com/benmccann/import.meta.url-with-query-params

Steps to reproduce

Run npm install followed by npm run dev

System Info

npmPackages:
    vite: ^4.3.2 => 4.3.3

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions