【发布时间】:2019-02-04 13:51:34
【问题描述】:
我关注了 PSPDFKit React tutorials available here
我还将我的文件复制到 /public 目录,并将除 pspdfkit.js 之外的所有内容从 node_modules 移到那里,并更新了我的 baseUrl 变量以指向该目录。
然后,当我尝试在 localhost:3000 上使用 npm run start 在本地运行我的 react 应用程序时,我从 PSPDFkit 获得了加载动画,但它挂断了并且控制台给了我一个错误:
使用 WASM 方法
开始http://localhost:3000/pspdfkit-lib/pspdfkit.wasm下载。
未捕获(承诺中)类型错误:无法在“WebAssembly”上执行“编译”:响应 MIME 类型不正确。预期的“应用程序/wasm”。
I know there is a trouble-shooting topic on it, found here,但我仍然无法解决我的问题。
有什么想法吗?
我的组件文件:
import React, {Component} from 'react';
import PSPDFKitWeb from 'pspdfkit';
class PSPDFKit extends Component {
constructor(props, context){
super(props, context);
this._instance = null;
this._container = null;
this.onRef = this.onRef.bind(this);
this.load = this.load.bind(this);
this.unload = this.unload.bind(this);
}
onRef(container) {
this._container = container;
}
//function that loads PSPDFKit library when
async load(props) {
console.log(`Loading ${props.pdfUrl}`);
this._instance = await PSPDFKitWeb.load({
disableWebAssemblyStreaming: true,
pdf: props.pdfUrl,
container: this._container,
licenseKey: props.licenseKey,
baseUrl: props.baseUrl
});
console.log("Successfully mounted PSPDFKit", this._instance);
}
unload() {
PSPDFKitWeb.unload(this._instance || this._container);
this._instance = null;
}
componentDidMount() {
this.load(this.props);
}
componentDidUpdate(nextProps) {
this.unload();
this.load(nextProps);
}
componentWillUnmount() {
this.unload();
}
render() {
return <div ref={this.onRef} style={{ width: "100%", height: "100%", position: "absolute" }} />;
}
}
export default PSPDFKit
【问题讨论】:
标签: reactjs create-react-app webassembly pspdfkit