构建版本的 react 应用程序提供了错误的 CSS 和 JS 文件链接 [英] Build version of react app giving wrong links to CSS and JS files
问题描述
我一直在开发一个名为 Simple-portfolio 的简单 React 项目,
Github 存储库:https://github.com/Devang47/simple-portfolio现场网址:https://simple-portfolio.pages.dev/
I've been working on a simple React project named Simple-portfolio,
Github repo: https://github.com/Devang47/simple-portfolio
live site url: https://simple-portfolio.pages.dev/
此项目在开发服务器中运行良好,但在构建应用程序后,在 index.html
中,指向其他文件的链接出错.例如:
This project is working fine in the development server but after building the app, in index.html
the link to other files is getting wrong. for ex:
// Wrong:
<link rel="icon" type="image/png" sizes="16x16" href="./simple-portfolio/favicon-16x16.png"/>
expected:
<link rel="icon" type="image/png" sizes="16x16" href="./favicon-16x16.png"/>
生产构建控制台上的错误:
Errors on the console of production build:
The script from "https://simple-portfolio.pages.dev/simple-portfolio/static/js/3.f84cd7e8.chunk.js" was loaded even though its MIME type ("text/html") is not a valid JavaScript MIME type.
The script from "https://simple-portfolio.pages.dev/simple-portfolio/static/js/main.2f259d87.chunk.js" was loaded even though its MIME type ("text/html") is not a valid JavaScript MIME type.
The stylesheet https://simple-portfolio.pages.dev/simple-portfolio/static/css/main.f6d0acc0.chunk.css was not loaded because its MIME type, "text/html", is not "text/css".
Uncaught SyntaxError: expected expression, got '<'
Uncaught SyntaxError: expected expression, got '<'
到目前为止我所尝试的:
What I've tried till now:
- 删除 node_modules
- 删除锁定文件
- 针对类似问题全面搜索堆栈溢出
- 在另一个分支上尝试
推荐答案
您的应用已部署到 https://simple-portfolio.pages.dev/ 这是域的根,但 homepage
设置为 http://Devang47.github.io/simple-portfolio/ 有不同的路径.
Your app is deployed to https://simple-portfolio.pages.dev/ which is the root of the domain, but the homepage
is set to http://Devang47.github.io/simple-portfolio/ which has a different path.
要解决此问题,请从 package.json
中删除 homepage
,重建您的应用,然后将其重新部署到 Cloudflare Pages.
To fix this, delete homepage
from package.json
, rebuild your app, and redeploy it to Cloudflare Pages.
这篇关于构建版本的 react 应用程序提供了错误的 CSS 和 JS 文件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!