Javascript 响应意外的令牌生成
我在制作react pdf时遇到了一些问题。我正在使用的应用程序在使用webpack dev server构建时运行良好,但在使用生产webpack构建应用程序时,react pdf的worker无法正常工作。有一个错误Javascript 响应意外的令牌生成,javascript,reactjs,webpack,react-pdf,Javascript,Reactjs,Webpack,React Pdf,我在制作react pdf时遇到了一些问题。我正在使用的应用程序在使用webpack dev server构建时运行良好,但在使用生产webpack构建应用程序时,react pdf的worker无法正常工作。有一个错误Uncaught SyntaxError:Unexpected token'{ const itemName=props.match.params.itemName; const pageTitle=项目名称; const file=props.location.state.ur
Uncaught SyntaxError:Unexpected token'{
const itemName=props.match.params.itemName;
const pageTitle=项目名称;
const file=props.location.state.url;
const type=props.location.state.type;
常量[状态,设置状态]=使用状态({
数值:0
});
const onError=(e)=>{
警报(例如,“文件查看器中的错误”);
}
constOnDocumentLoadSuccess=({numPages})=>{
设置状态({numPages});
}
返回(
{type==='pdf'?
{[…数组(state.numPages).keys()].map((页面)=>(
))}
:type==='video'?
:'未指定文件'}
);
}
您有任何更新吗?我也面临同样的问题。你有什么最新消息吗?我也面临同样的问题。
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`
import { Document, Page, pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = 'node_modules/pdfjs-dist/build/pdf.worker.js';
const Item = (props) => {
const itemName = props.match.params.itemname;
const pageTitle = itemName;
const file = props.location.state.url;
const type = props.location.state.type;
const [state, setState] = useState({
numPages: 0
});
const onError = (e) => {
alert(e, 'error in file-viewer');
}
const onDocumentLoadSuccess = ({ numPages }) => {
setState({ numPages });
}
return (
<>
<PageHeader pageTitle={pageTitle}/>
<div className="container-padding">
{type === 'pdf' ?
<Document
file={file}
onLoadSuccess={onDocumentLoadSuccess}
>
{[...Array(state.numPages).keys()].map((page) => (
<Page pageNumber={page + 1} key={page + 1} />
))}
</Document>
:type === 'video'?
<video
controls
key="video"
autoPlay
playsInline
src={file}
onError={onError}>
</video> : 'No file specified'}
</div>
<br />
</>
);
}