Skip to content

Vitest fails when importing wasm module with filename.wasm?init #6723

@MCMattia

Description

@MCMattia

Describe the bug

I'm importing a wasm module in a .ts file like so:

import init from '$lib/fileName.wasm?init';

Importing the wasm file follows the recommended way in the vite documentation:
https://vite.dev/guide/features.html#webassembly

The wasm module was compiled with emcc:

emcc -s EXPORTED_FUNCTIONS='["_function"]' --no-entry -std=c++20 -O1 src_cpp/file.cpp -o src/lib/fileName.wasm

I'm then importing a function that initializes the wasm module in a test file:

import {
	func
} from '$lib/file2';
import { describe, it, expect } from 'vitest';`

Running the test with:

pnpm run test

I get the error:

TypeError: Failed to parse URL from /src/lib/fileName.wasm?init
Caused by: TypeError: Invalid URL
Serialized Error: { code: 'ERR_INVALID_URL', input: '/src/lib/fileName.wasm?init' }

Reproduction

Can't reproduce wasm on StackBlitz as far as I know.

System Info

Confidential

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-to-be-discussedEnhancement under consideration (priority)

    Type

    No type

    Projects

    Status

    P2 - 4

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions