I'm trying to use mediainfo.js with React.js.
Looking at the usage example in React.js of the above site, it is set by "webpack.config.js".
However, when I build the environment using create-react-app
, "webpack.config.js" is wrapped and it seems that it can not be edited without executing the 'eject' command.
If you use npm package "react-app-rewired", you can edit it without executing the reject command, so I tried it.
// config-override.js (overwrites webpack.config.js)
const { resolve } = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const wasmFile = resolve(
__dirname,
'node_modules',
'mediainfo.js',
'dist'
);
const dist = resolve('build', 'static', 'js');
// template from https://www.npmjs.com/package/react-app-rewired
module.exports = {
webpack: function(config, env) {
config.plugins.push(new CopyPlugin({
patterns: [
{ from: wasmFile, to: dist },
],
}),)
return config;
},
}
Here is the whole project.
https://github.com/ottonove/test_mediainfo
The one generated by "npm run build" works normally, but when I run it by "npm run start", the following error occurs.
Uncaught (in promise) RuntimeError: abort(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -s ASSERTIONS=1 for more info.
The following warning is also issued.
wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
How do I set it to work with "npm run start"?
I would appreciate it if you could teach me.