Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
wast-loader (webpack rule)
✓ module.exports = { module: { rules: [{ test: /\.wast$/, loader: 'wast-loader', type: 'webassembly/experimental' }] } };
✗ module.exports = { module: { rules: [{ test: /\.wast$/, loader: 'wast-loader' }] } };
Webpack 4 requires type: 'webassembly/experimental' for webassembly modules. Omitting it will cause errors.
CommonJS require
✓ const wasm = require('./module.wast');
✗ import wasm from './module.wast';
This is a webpack loader, so the import style depends on webpack config. The loader output is a wasm module object.
ESM import
✓ import wasm from './module.wast';
✗ const wasm = require('./module.wast');
If using webpack with type: 'module', ESM imports are preferred. The default export is the wasm module.
TypeScript type import
✓ import type WasmModule from './module.wast';
✗ import WasmModule from './module.wast';
For type-only imports to avoid bundling issues. Requires a type declaration for .wast files.
Shows a minimal webpack 4 config using wast-loader with .wast files, a simple add.wat module, and usage in entry point.
// webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.wast$/,
loader: 'wast-loader',
type: 'webassembly/experimental',
},
],
},
};
// src/add.wat
(module
(func (export "add") (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.add
)
)
// src/index.js
import wasmModule from './add.wast';
wasmModule.instance.then(instance => {
const { add } = instance.exports;
console.log(add(2, 3)); // 5
});
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Missing type: 'webassembly/experimental' in webpack rule or loader not configured; webpack treats .wast as a regular file.
fixEnsure rule has loader: 'wast-loader' and type: 'webassembly/experimental' in webpack 4.
Error: Cannot find module '@webassemblyjs/ast'
Missing peer dependency; wast-loader requires @webassemblyjs packages that are not automatically installed.
fixRun: npm install @webassemblyjs/ast @webassemblyjs/wast-parser @webassemblyjs/wast-printer @webassemblyjs/helper-wasm-bytecode
TypeError: wasmModule.instance is undefined
The loader returns a Module object that may not have an instance if used incorrectly (e.g., accessing .instance before the promise resolves).
fixUse wasmModule.then(module => { const instance = module.instance; ... }) or await wasmModule. Audit
Dependencies
@webassemblyjs/astrequiredParsing and manipulating WAT AST
@webassemblyjs/wast-parserrequiredParse .wast files into AST
@webassemblyjs/wast-printerrequiredPrint AST back to text format
@webassemblyjs/helper-wasm-bytecoderequiredConvert WAT AST to wasm bytecode