Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 19, 2026

WASM-based Prettier plugins (e.g., assemblyscript-prettier) fail in v12.1.0+ with WebAssembly.instantiateStreaming is not a function. The ESM migration in v12.1.0 introduced dynamic import() with file URLs, which creates a module context where Node.js doesn't expose WebAssembly.instantiateStreaming.

Changes

  • Added polyfill in PrettierDynamicInstance.ts before dynamic imports
  • Polyfill provides WebAssembly.instantiateStreaming using WebAssembly.instantiate + arrayBuffer() fallback
  • Applied globally once before loading Prettier modules
  • Added comprehensive test suite in wasm-polyfill.test.ts to verify polyfill behavior
function polyfillWebAssemblyInstantiateStreaming(): void {
  const wasm = (globalThis as any).WebAssembly;
  if (typeof wasm !== "undefined" && !wasm.instantiateStreaming) {
    wasm.instantiateStreaming = async function (source, importObject) {
      const response = await source;
      const bytes = await response.arrayBuffer();
      return wasm.instantiate(bytes, importObject);
    };
  }
}

Testing

  • ✅ Polyfill is applied when WebAssembly.instantiateStreaming is missing
  • ✅ Existing implementations are not overridden
  • ✅ Polyfilled function correctly uses WebAssembly.instantiate with arrayBuffer()

Non-WASM plugins unaffected. No behavioral changes to existing functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>v12.1.0 break some plugin</issue_title>
<issue_description>### Preflight Checklist

Issue Summary

after upgrade to v12.1.0, plugin based on wasm does not work anymore

["ERROR" - 08:41:43] WebAssembly.instantiateStreaming is not a function
TypeError: WebAssembly.instantiateStreaming is not a function
	at file:///Users/caicongcong/dev/warpo/node_modules/assemblyscript-prettier/node_modules/assemblyscript/dist/assemblyscript.js:9:38049

Reproduction Repository

https://github.com/wasm-ecosystem/warpo

Steps to Reproduce

  1. clone the repo
  2. change some format in assemblyscript/src/...
  3. format with plugin

Expected Behavior

plugin with wasm can be load successfully

Actual Behavior

error

Operating System

macOS

VS Code Version

Version: 1.108.1 Commit: 585eba7c0c34fd6b30faac7c62a42050bfbc0086 Date: 2026-01-14T14:55:44.241Z Electron: 39.2.7 ElectronBuildId: 12953945 Chromium: 142.0.7444.235 Node.js: 22.21.1 V8: 14.2.231.21-electron.0 OS: Darwin arm64 25.2.0

Prettier Extension Version

v12.1.0

Prettier Version

3.6.2

Prettier Extension Logs

["ERROR" - 08:41:43] WebAssembly.instantiateStreaming is not a function
TypeError: WebAssembly.instantiateStreaming is not a function
	at file:///Users/caicongcong/dev/warpo/node_modules/assemblyscript-prettier/node_modules/assemblyscript/dist/assemblyscript.js:9:38049

Prettier Configuration

printWidth: 120
tabWidth: 2
useTabs: false
semi: true
singleQuote: false
quoteProps: "as-needed"
jsxSingleQuote: false
trailingComma: "es5"
bracketSpacing: true
arrowParens: "always"
vueIndentScriptAndStyle: false
endOfLine: "lf"
plugins:
  - assemblyscript-prettier
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix WebAssembly plugin compatibility issue after v12.1.0 upgrade Add WebAssembly.instantiateStreaming polyfill for Node.js ESM context Jan 19, 2026
Copilot AI requested a review from ntotten January 19, 2026 13:56
@ntotten
Copy link
Member

ntotten commented Jan 19, 2026

@copilot we need a test case for this

Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot we need a test case for this

Added test case in commit 393f4c3. The test file wasm-polyfill.test.ts includes three test cases that verify:

  1. The polyfill is applied when WebAssembly.instantiateStreaming is missing
  2. Existing implementations are not overridden
  3. The polyfilled function correctly uses WebAssembly.instantiate with arrayBuffer()

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.

v12.1.0 break some plugin

2 participants