在Netlify上部署时无法显示来自app.js的内容(npm运行版本)

时间:2019-08-31 17:33:58

标签: reactjs deployment web-deployment netlify

当我尝试在Netlify上托管(npm run build)时,我无法通过app.js文件获取内容

这是我的package.json文件的样子:

{
  "name": "nasa-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "dotenv": "^8.1.0",
    "jquery": "^1.9.1",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-helmet": "^5.2.1",
    "react-scripts": "0.9.5"
  },
  "devDependencies": {
    "babel-eslint": "^9.0.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.1",
    "eslint-config-prettier": "^4.3.0",
    "eslint-config-wesbos": "0.0.19",
    "eslint-plugin-html": "^5.0.5",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.0",
    "eslint-plugin-react": "^7.14.3",
    "eslint-plugin-react-hooks": "^1.7.0",
    "prettier": "^1.18.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "description": "**A Day In The Life On Mars**",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/able-leopard/a-day-in-the-life-on-mars.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/able-leopard/a-day-in-the-life-on-mars/issues"
  },
  "homepage": "https://github.com/able-leopard/a-day-in-the-life-on-mars#readme"
}


由于我仍然是新手,所以似乎无法发布屏幕截图,但是基本上所有托管版本的显示都是

<div id="root"><div/>,而本地版本实际上显示了我app.js中的所有内容

非常感谢!

1 个答案:

答案 0 :(得分:1)

在您的package.json中,您需要将homepage更改为"/"

这解决了您的问题:https://vigilant-bhabha-b3e068.netlify.com/ (此链接不再有效,这只是为了证明我让它适用于OP,而不是试图劫持他们的部署)

一旦您看到此消息,请告诉我,我将删除我创建的Netlify应用程序和我创建的仓库。


为了证明这是可行的:

URL: enter image description here

站点: enter image description here

{
  ...
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/able-leopard/a-day-in-the-life-on-mars/issues"
  },
  "homepage": "/"
}