StackBlitz×ViteでRangeErrorが発生して起動しない問題の回避策

StackBlitzが起動しない問題の回避策

オンライン統合開発環境(IDE)であるStackBlitz上で、ViteのReactスターターテンプレート等から新規プロジェクトを立ち上げようとすると、npm run devの実行時にクラッシュが発生し、開発サーバーが起動しないという問題が多発しています。

発生している事象

StackBlitz上のターミナルで「npm run dev」を実行すると、次のようなエラーログを出力してViteで起動できません。

~/projects/vitejs-vite-hjgy28fy
 npm install && npm run dev

added 154 packages in 1s

43 packages are looking for funding
  run `npm fund` for details

> vite-react-typescript-starter@0.0.0 dev
> vite

[rolldown] Downloading @rolldown/binding-wasm32-wasi@1.0.3 on WebContainer...
Packages: +7
+++++++
Progress: resolved 7, reused 0, downloaded 7, added 7, done

dependencies:
+ @rolldown/binding-wasm32-wasi 1.0.3 (1.1.0 is available)

Done in 4.8s
(node:12) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12) ExperimentalWarning: WASI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
worker (tid = 43) sent an error! Invalid atomic access index
RangeError: Invalid atomic access index
    at Object.storeSizeTypeValue (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:1218:29)
    at Object.pushQueue (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:990:28)
    at eval (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:1040:36)
    at Object.execute (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:1094:36)
    at Object.push (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:1029:33)
    at napi_call_threadsafe_function (/tmp/rolldown-1.0.3/node_modules/.pnpm/@emnapi+core@1.10.0/node_modules/@emnapi/core/dist/emnapi-core.cjs.js:1612:31)

Node.js v22.22.0

~/projects/vitejs-vite-hjgy28fy 7s

StackBlitz×ViteでRangeErrorが発生して起動しない環境(修正前)

発生している問題の原因

この問題の核心は、「次世代高速ビルドツールのテスト運用」と「ブラウザ型Node.js環境の制限」の衝突にあります。

1. Viteの新コア「Rolldown」の試験導入

現在、Vite開発チームは現在のビルドエンジン(Rollup / esbuild)を、Rust製の超高速な新エンジン「Rolldown」へと移行する開発を進めています。

一部の新しいテンプレートや特定のバージョン(Vite 6〜8系の実験的機能など)では、このRolldownがデフォルト、あるいは特定の条件下で裏で自動的にダウンロードされるようになっています。

2. WebContainer(WASM / WASI)の互換性限界

StackBlitzは、ブラウザ上でNode.jsを高速に模倣して動かす「WebContainer」という特殊な技術を採用しています。

ネイティブなRust製ツールであるRolldownをブラウザ上で動かすため、StackBlitz上ではWASM版(@rolldown/binding-wasm32-wasi)がロードされます。

しかし、このWASM版Rolldownがマルチスレッド処理やメモリ共有(@emnapi/core)を行う際、WebContainer側の実験的な機能である「WASI(WebAssembly System Interface)」のメモリ管理制限に引っかかってしまい、Invalid atomic access index(不正なアトミックアクセスインデックス)という低レイヤーのメモリ範囲外エラーを引き起こしています。

StackBlitzが起動しない問題の回避策

この問題はユーザー側のコードが悪いわけではなく、StackBlitz環境の互換性バグです。

そのため、「Rolldown(WASM版)を強制的にロードさせない安定バージョンに戻す」のが最も確実な対処法になります。

やり方はpackage.jsonの@vitejs/plugin-react、typescript、viteを以下の安定バージョンに戻して保存します。

※ Vite + React + TypeScriptの場合の設定なので、ViteだけのVanilla JSならReactとTypeScriptの対応は不要

package.json
{
  "name": "vite-react-typescript-starter",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc -b && vite build",
    "lint": "eslint .",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^19.2.7",
    "react-dom": "^19.2.7"
  },
  "devDependencies": {
    "@eslint/js": "^10.0.1",
    "@types/node": "^24.13.1",
    "@types/react": "^19.2.17",
    "@types/react-dom": "^19.2.3",
    "@vitejs/plugin-react": "^5.1.1",
    "eslint": "^10.4.1",
    "eslint-plugin-react-hooks": "^7.1.1",
    "eslint-plugin-react-refresh": "^0.5.2",
    "globals": "^17.6.0",
    "typescript": "^5.4.2",
    "typescript-eslint": "^8.60.1",
    "vite": "^5.4.11"
  }
}

あとはStackBlitz内のターミナルで、以下のコマンドを実行すればViteで起動できます。

rm -rf node_modules package-lock.json && npm install && npm run dev

まとめ

WebContainerのような最先端のブラウザ技術と、Rolldownという最先端のビルドツールの組み合わせは非常に強力ですが、過渡期においては今回のようなWASM/WASI周りの予期せぬエラーが発生しがちです。

現在のViteで起動できない問題はStackBlitzの関係者も把握しているので、今月中には修正されると思います。

もしも今すぐViteを起動して閲覧可能な状態にしたい場合は、慌てずに一歩手前の安定バージョン(Vite 5系)への固定を試してみてください。