Vite's ?url Suffix Returns a File Path, Not Executable JavaScript
Vite's ?url import modifier is a four-character suffix that changes how a file is handled during bundling, turning it into an asset URL string rather than loading it as executable code. Developers who mistakenly append ?url to a jQuery import receive a plain string, not jQuery's API, causing a TypeError if they attempt to call it as a function. The feature is intended for use cases where a browser API — such as CSS.paintWorklet.addModule() or a script's src attribute — requires a URL rather than a module. During development the string may point to the source file directly, while production builds can apply hashed filenames or inline the asset as a data URI. For standard module usage, the ?url suffix should be omitted, and jQuery 4 users are advised to import from the package's public jquery/slim entry point instead of reaching into the dist folder.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in