Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define MIME types with Create-React-App's node server?

I'm trying to deal with this WebAssembly note: "Note: To run with instantiateStreaming and compileStreaming, you need your webserver to serve .wasm file with application/wasm MIME type. The https crate can be used to serve files from localhost, and includes the application/wasm MIME type out of the box."

Indeed, I get a MIME error in the JS console. A Google search revealed no way to configure this. Mozilla recommends instantiateStreaming over the depricated WebAssembly.instantiate. The latter doesn't work for me either, if using stdweb or bindgen: It wants a second argument which I'm not sure how to provide.

like image 330
Turtles Are Cute Avatar asked May 24 '18 20:05

Turtles Are Cute


People also ask

How do I specify a MIME type?

In the Connections pane, go to the site, application, or directory for which you want to add a MIME type. In the Home pane, double-click MIME Types. In the MIME Types pane, click Add... in the Actions pane. In the Add MIME Type dialog box, add the file name extension and MIME type, and then click OK.

What is mime in node JS?

Mime (npm node-mimejs) is a capturing mock library for Node. js.

Does create react app use node?

ReactJS uses Node. js, a JavaScript runtime, to build your JavaScript code. Basically, the ReactJS is a JavaScript framework which needs the help of node js and npm(Package manager) to tell the native side(Android/iOS) that these are packages I need to run my app. And it adds all the dependencies needed to run the app.


1 Answers

Unfortunately you're working on the bleeding edge here! WebAssembly streaming compilation is a very new feature that is only currently supported in FireFox and Chrome.

You are right that it depends on files being server with the correct mime-type. The changes required to make this happen being made:

  • node-mime - which is used by many projects (including webpack dev server) to provide mime type based on file extension, was updated to support wasm in Dec 2017 in v2.3.1
  • webpack-dev-middleware was updated in Nov 2017 to support wasm file extension in v3.1.3

However, these are both up-stream dependencies of create-react-app, via react-scripts. The bleeding edge version of react-scripts has a dependency on webback-dev-middleware that supports wasm, however this hasn't been released yet. The latest version on npm uses an older version.

For now, I'd turn of streaming compilation until these changes make it into 'production'.

like image 52
ColinE Avatar answered Oct 06 '22 00:10

ColinE