当我将react项目部署到Surge中时,构建是成功的,并且可以获得应用URL。但是当我链接到URL时,我可以在inspect控制台中看到一个空白页面和一些错误:
Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.css:1
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: the server responded with a status of 404 (Not Found) manifest.json:1
Manifest: Line: 1, column: 1, Syntax error. manifest.json:1
Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) 3.138a0231.chunk.css
Failed to load resource: the server responded with a status of 404 (Not Found) main.bd0d3f99.chunk.css:1
字符串
下面是我的package.json
文件中的react启动脚本。
"scripts": {
"build": "REACT_APP_BACKEND=true PUBLIC_URL='/sing-app-react' node scripts/build.js",
"start": "node scripts/start.js",
"start:backend": "REACT_APP_BACKEND=true node scripts/start.js",
"test": "node scripts/test.js"
},
型
以及导致错误https://lopsided-dinner.surge.sh/sing-app-react/static/css/3.138a0231.chunk.css
的css文件的链接地址。
2条答案
按热度按时间des4xlb01#
第一个月
这个网站的网址由React脚本应该是类似
https://your domain/static/css...
删除构建脚本中的PUBLIC_URL并再次运行构建。
它将构建源代码引导到/static/....
希望这对你有意义!
v2g6jxz62#
在我的例子中,问题是我从
build
文件夹中提供我的react项目,而.gitignore
文件中有/build
。我从.gitignore文件中删除了/build
,它工作了。