我的 React 应用程序在 Heroku 上构建和部署后,我在控制台中收到这些错误。
Refused to apply style from 'https://radiant-tor-66940.herokuapp.com/index.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Failed to load resource: the server responded with a status of 404 (Not Found) main.3174e036.chunk.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) 1.b1e0c624.chunk.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) main.3174e036.chunk.js:1
Failed to load resource: the server responded with a status of 404 (Not Found) manifest.json:1
Manifest: Line: 1, column: 1, Unexpected token. manifest.json:1
该index.js
文件位于/client/build/
我的 Heroku 服务器上。这是我的 Express 服务器发送的文件。服务器正在发送这个index.html
文件,但文件本身没有找到它需要的资源。
这会导致加载空白应用程序的问题。由于某种原因index.html
,没有chunk.js
在/client/build/static/js
. 他们肯定在那里,我可以确认heroku run bash
并检查目录。
当我index.html
在浏览器中检查文档时,我可以在底部看到脚本标签调用chunk.js
文件的位置/static/js
:
这是package.json
应用程序的根目录的样子:
"scripts": {
"test": "jest",
"start": "node server/server.js",
"heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
},
"engines": {
"node": "~9.10.1",
"npm": "~5.6.0"
}
这是package.json
位于 中的 React 应用程序的/client
样子:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"lodash": "^4.17.11",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.3",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"styled-components": "^4.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"proxy": "http://localhost:8000/"
}
这是 Heroku 构建后的文件结构:
- 第一张图:
/client
目录 - 图二:
/client/build
目录 - 第三张图:
/client/build/static/js
目录