PSPDFKIT : 不正确的响应 MIME 类型



我遵循了此处提供的PSPDFKit React教程

我还将我的文件复制到/public 目录,并将除 pspdfkit 以外的所有内容.js从那里node_modules移走,并更新了我的baseUrl变量以指向此目录。

然后,当我尝试在localhost:3000上使用npm run start在本地运行我的 react 应用程序时,我从 PSPDFkit 获得加载动画,但它挂断并且控制台给了我一个错误:

使用 WASM 方法

开始 http://localhost:3000/pspdfkit-lib/pspdfkit.wasm 下载。

未捕获(在承诺中(类型错误:无法在"WebAssembly"上执行"编译":响应 MIME 类型不正确。预期的"应用程序/wasm"。

我知道这里有一个故障排除主题,但我仍然无法解决我的问题。

有什么想法吗?

我的组件文件:

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

对于遇到相同问题的任何人来说。您可以通过禁用Web程序集流(这会导致错误。 反应脚本webpack不以正确的MIME类型提供wasm文件(。 只需在加载方法上将禁用WebAssemblyStreaming传递给true:

this._instance = await PSPDFKitWeb.load({
pdf: props.pdfUrl,
container: this._container,
licenseKey: props.licenseKey,
baseUrl: props.baseUrl,
disableWebAssemblyStreaming: true, // <---- This here
});

看起来问题是由 wasm 文件未以正确的内容类型提供引起的

,此处建议:https://pspdfkit.com/guides/web/current/pspdfkit-for-web/troubleshooting/#response-has-unsupported-mime-type-error打开package.json文件并将react-scripts升级到1.1.5,删除node_modules,然后重新安装。

将来,请与 pspdfkit.com/support/request 联系,我们的支持团队将为您提供帮助。

相关内容

最新更新