我使用 Create-React-App (CRA) 创建了一个简单的应用程序。问题是,即使应用程序在我的本地主机上运行得很好(即使用 npm start
后),当我尝试将页面发布到 gh-pages ( npm run build
和 npm run deploy
)时,我无法使用 URL 加载页面。一开始我什至在控制台中没有看到任何错误,但过了一会儿(或更具体地说,在控制台中打开“时间轴”选项卡后),我看到以下错误。
Failed to create temp file 18 : It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.
我确实在本地开发环境中看到了此警告,
[Violation] Long running JavaScript task took 229ms
缩小后的bundle.js 文件大小约为4MB。但我想这不是问题,因为我的其他项目也有同样的警告,而且它们发布得很好。
我也相当有信心这是一个与 JavaScript 更多相关的问题,而不是与 CRA 相关的问题。我在某处读到这可能是资源网络映射问题。但到目前为止,我不太确定这意味着什么或如何解决它。
最佳答案
只是为了回答我自己的问题,以防其他人来到这里。
问题出在我使用 react-router
的方式上。我最初使用的是 browserHistory
而不是 hashHistory
。
根据文档,
GitHub Pages doesn’t support routers that use the HTML5 pushState history API under the hood (for example, React Router using browserHistory). This is because when there is a fresh page load for a url like http://user.github.io/todomvc/todos/42, where /todos/42 is a frontend route, the GitHub Pages server returns 404 because it knows nothing of /todos/42.
更多信息可以found here .
关于javascript - 发布的 github 页面上出现 "Failed to create temp file 18"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43046437/