小编Ric*_*ado的帖子

TypeError:无法在'WebAssembly'上执行'compile':错误的响应MIME类型.期待'申请/ wasm'

我正在尝试使用Chrome上的fetch api加载.wasm文件,并使用express提供html文件.但chrome不允许我加载文件:

'未捕获(承诺)TypeError:无法在'WebAssembly'上执行'compile':错误的响应MIME类型.预计'申请/ wasm'.'

这是我的文件:

/public/index.html

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script type="text/javascript">
          WebAssembly.instantiateStreaming(fetch('http://localhost:3000/simple.wasm'))
      .then(obj => {
       console.log(obj.instance.exports.add(1, 2));  // "3"
      });
    </script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

快递服务:

/index.js

const express = require('express')
express.static.mime.define({'application/wasm': ['wasm']})
var app = express();

app.use('/', express.static('public'));

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})
Run Code Online (Sandbox Code Playgroud)

我可以在提供.wasm文件时添加新的mime类型来表达吗?或允许铬接受它?我对如何解决它没有任何想法^^

请参阅:http://kripken.github.io/emscripten-site/docs/compiling/WebAssembly.html

Web server setup
To serve wasm in the most efficient way over the network, make sure your web server …
Run Code Online (Sandbox Code Playgroud)

express webassembly

15
推荐指数
3
解决办法
7427
查看次数

标签 统计

express ×1

webassembly ×1