webpack/webpack · error · Error
unknown type: ${globalType.valtype}
Error message
unknown type: ${globalType.valtype} What it means
The sync WebAssembly generator rewrites every imported global into a mutable local with a default zero-initializer. createDefaultInitForGlobal only knows how to synthesize that initializer for numeric value types whose valtype starts with 'i' (i32/i64) or 'f' (f32/f64). A global whose valtype is a reference type (externref/funcref/anyref) or a SIMD vector (v128) has no numeric default, so the rewrite aborts. This only fires under experiments.syncWebAssembly; the async path does not rewrite globals this way.
Source
Thrown at lib/wasm-sync/WebAssemblyGenerator.js:163
/**
* Creates an init instruction for a global type
* @param {t.GlobalType} globalType the global type
* @returns {t.Instruction} init expression
*/
const createDefaultInitForGlobal = (globalType) => {
if (globalType.valtype[0] === "i") {
// create NumberLiteral global initializer
return t.objectInstruction("const", globalType.valtype, [
t.numberLiteralFromRaw(66)
]);
} else if (globalType.valtype[0] === "f") {
// create FloatLiteral global initializer
return t.objectInstruction("const", globalType.valtype, [
t.floatLiteral(66, false, false, "66")
]);
}
throw new Error(`unknown type: ${globalType.valtype}`);
};
/**
* Rewrite the import globals:
* - removes the ModuleImport instruction
* - injects at the same offset a mutable global of the same type
*
* Since the imported globals are before the other global declarations, our
* indices will be preserved.
*
* Note that globals will become mutable.
* @param {object} state transformation state
* @param {AST} state.ast Module's ast
* @param {t.Instruction[]} state.additionalInitCode list of addition instructions for the init function
* @returns {ArrayBufferTransform} transform
*/
const rewriteImportedGlobals = (state) => (bin) => {
const additionalInitCode = state.additionalInitCode;View on GitHub (pinned to 318421ea8a)
Solutions
- Switch experiments.syncWebAssembly to experiments.asyncWebAssembly; the async generator does not rewrite imported globals and accepts reference/SIMD types.
- Rebuild the wasm module without the offending imported global (disable reference-types/SIMD in the toolchain, e.g. rustc -C target-feature=-reference-types,-simd128, or define the global inside the module instead of importing it).
- Filter the offending .wasm out of the sync-wasm pipeline (different module.rules test) and load it through a side channel that does not require global rewriting.
Example fix
// before
module.exports = {
experiments: { syncWebAssembly: true }
};
// after
module.exports = {
experiments: { asyncWebAssembly: true }
}; Defensive patterns
Strategy: validation
Validate before calling
// Pre-build: decode the wasm and reject modules whose imported globals
// use a non-numeric valtype before webpack's sync generator trips on them.
const { decode } = require('@webassemblyjs/wasm-parser');
const t = require('@webassemblyjs/ast');
function assertNoUnsupportedImportedGlobals(wasmBuffer) {
const ast = decode(wasmBuffer, { ignoreCodeSection: true, ignoreDataSection: true });
t.traverse(ast, {
ModuleImport({ node }) {
if (t.isGlobalType(node.descr)) {
const v = node.descr.valtype;
if (v[0] !== 'i' && v[0] !== 'f') {
throw new Error(`Unsupported imported global type ${v} in ${node.module}:${node.name}; rebuild without reference-types/SIMD globals or use asyncWebAssembly.`);
}
}
}
});
}
// assertNoUnsupportedImportedGlobals(fs.readFileSync('./module.wasm')); Type guard
/** @param {string} valtype wasm global value type
* @returns {boolean} true when createDefaultInitForGlobal can handle it */
function isNumericValtype(valtype) {
return valtype[0] === 'i' || valtype[0] === 'f';
} Prevention
- Prefer experiments.asyncWebAssembly over the deprecated syncWebAssembly experiment; the async path does not rewrite imported globals.
- If you control the wasm toolchain, disable reference-types and simd128 when targeting the sync pipeline.
- Pin your @webassemblyjs/* versions to the ones webpack depends on so decode() and the generator agree on the valtype alphabet.
When it happens
Trigger: Bundling a .wasm module that imports a global of a non-numeric type (v128, externref, funcref) while experiments.syncWebAssembly is enabled. The generator's rewriteImportedGlobals transform calls createDefaultInitForGlobal for each imported global during WebAssemblyGenerator.generate.
Common situations: Using the deprecated experiments.syncWebAssembly experiment with a modern wasm module that uses reference-types or SIMD globals; upgrading a Rust/AssemblyScript toolchain that started emitting reference-type globals; switching a build from asyncWebAssembly to syncWebAssembly and hitting a module the async path tolerated.
Related errors
- Universal wasm loading type is only supported by asynchronou
- optimization.usedExports can't be used with cacheUnaffected
- WebAssemblyParser input must be a Buffer
- Source phase imports require valid WebAssembly modules. Inva
- WebAssemblyParser input must be a Buffer
AI-assisted analysis of webpack/webpack@318421ea8a (2026-08-03).
Data as JSON: /data/errors/7db677aa341e4af4.json.
Report an issue: GitHub.