【问题标题】:How to fix breaking change on homepage after update react-scripts (create react app)更新反应脚本后如何修复主页上的重大更改(创建反应应用程序)
【发布时间】:2020-12-29 14:05:54
【问题描述】:

根据How to upgrade a React project built with create-react-app,我已将 react-scripts 从 v1.1.4 更新到 v3.4.3。但是,主页上有一个问题我无法正确解决。

在之前的 package.json 中,我有 "homepage": "/temp_project/resources" 在我将 react-scripts 更新到 v3.4.3 之后,一切正常,除了 当 npm start ("start": "react-scripts start") 时,路径将变为 http://localhost:3000/temp_project/resources 这是意料之中的。 (预计有 http://localhost:3000/ ) Hot fix = 每次手动将路径更改为 http://localhost:3000/

如果我将"homepage": "/temp_project/resources" 更改为"homepage": "/",那么我的http://localhost:8080/temp_project(索引页)就会变成一个空白页。我的 npm start ("start": "react-scripts start") 工作正常。

我该怎么办??对不起,如果这是一个愚蠢的问题。谢谢。

补充:

这是一个使用 eirslett/frontend-maven-plugin 的 maven spring boot 项目 和maven-resources-plugin

package.json

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8080",
  "homepage": "/temp_project/resources",
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]

【问题讨论】:

    标签: reactjs npm create-react-app package.json


    【解决方案1】:

    您可以试试"homepage": "." 或者"homepage": "./" 吗...如果有帮助,请告诉我

    【讨论】:

    • 感谢您的评论。我已经尝试了它们,并且它们都在 npm start (3000) 中完美运行,但是 8080 索引页面仍然是空白的,不被接受。
    • 你能把package.json和项目文件夹结构贴出来吗?
    • 在问题中添加了补充
    • 我更新到“主页”后问题终于解决了:“../resources”。你的答案应该是正确的。非常感谢。
    猜你喜欢
    • 2022-01-14
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 2021-01-20
    相关资源
    最近更新 更多