Skip to content

Conversation

@PendingReality
Copy link
Contributor

Add Vite plugin to remove unnecessary import.meta.url argument from data: URLs during build.

Problem

wasm-pack generates: new URL("data:...", import.meta.url)

The import.meta.url argument is unnecessary for data: URLs and causes:

  • Webpack 5: "Invalid generator object" error
  • Vite: Incorrectly rewrites URL as filesystem path

Solution

Transform during build:

  • Before: new URL("data:...", import.meta.url)
  • After: new URL("data:...")

This allows Next.js/webpack users to import spark normally without errors.

Fixes #95

…jsdev#95)

Add Vite plugin to remove unnecessary `import.meta.url` argument from
data: URLs during build.

## Problem
wasm-pack generates: `new URL("data:...", import.meta.url)`

The `import.meta.url` argument is unnecessary for data: URLs and causes:
- Webpack 5: "Invalid generator object" error
- Vite: Incorrectly rewrites URL as filesystem path

## Solution
Transform during build:
- Before: `new URL("data:...", import.meta.url)`
- After: `new URL("data:...")`

This allows Next.js/webpack users to import spark normally without errors.

Fixes sparkjsdev#95
@dmarcos
Copy link
Contributor

dmarcos commented Dec 5, 2025

Thanks so much for this!

@dmarcos dmarcos merged commit 752cfaa into sparkjsdev:main Dec 5, 2025
2 checks passed
@mrxz
Copy link
Collaborator

mrxz commented Dec 5, 2025

This breaks the source-map. Should use magic-string to make the substitution and generate the right mapping.

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.

Nextjs import / webpack

3 participants