我如何获得我的nodejs应用程序部署以加载下一个构建资源(404控制台错误删除了我网站上所有的React组件)

时间:2019-03-22 22:01:43

标签: node.js reactjs gcloud koa next.js

直接,相同的代码采用两种不同的部署方式:

npm在我的本地主机上运行开发 https://02e7822e.ngrok.io

在Google App Engine上启动(我假设) https://testing-234701.appspot.com/

我必须强调,这与正在部署的代码相同(显然是在package.json中专门为部署到App Engine而量身定制的),但是只有其中一个看起来正确。

我确定我们都认为package.json是一个问题,所以我将其包含在下面,但是如果有人遇到过类似的问题,nodejs应用程序在本地主机上看起来很好,但是看起来很糟糕,请让我知道!

Chrome控制台错误::无法加载资源:https://testing-234701.appspot.com/%7BsummarAIze%7D/_next/static/6MuW3BriROYrhZZCL~v03/pages/index.jsthe服务器响应,状态为404()

^注意,未加载的资源处理_next,因此它必须与next.js相关。

package.json

{
"name": "hps_prework",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "dev": "node app.js",
  "build": "next build",
  "start": "NODE_ENV=production && node app.js",
  "gcp-build": "npm run build",
  "deploy": "npm run build && gcloud app deploy"
},
"engines": {
  "node": ">10.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
  "@material-ui/core": "^3.9.2",
  "@material-ui/icons": "^3.0.2",
  "babel-loader": "^8.0.5",
  "jquery": "^3.3.1",
  "js-cookie": "^2.2.0",
  "koa": "^2.7.0",
  "koa-session": "^5.10.1",
  "next": "^8.0.3",
  "python-shell": "^1.0.7",
  "react": "^16.8.4",
  "react-dom": "^16.8.4",
  "react-scripts": "^2.1.8",
  "webpack": "^4.28.3"
},
"browserslist": [
  ">0.2%",
  "not dead",
  "not ie <= 11",
  "not op_mini all"
]

}

我还应该指出,我从以下上一个SO问题中获取了我的package.json脚本的灵感:Deployed a Next.js application to App Engine Standard [Nodejs] and got a 500 error

我正在使用gcloud app deploy部署到App Engine,从中记录的输出未显示任何问题。只是在加载网页时,所有内容都被破坏了。

最后,obligatory link到相关的github。

编辑:我也不知道这是否有帮助,但是我将相同的应用程序部署到了AWS Elastic Beanstalk上,过程非常容易。该网站的加载方式与在我的本地主机上加载的方式相同,AWS EB甚至允许用户更改用于运行该网站的npm命令,而Google App Engine似乎不支持该命令。

0 个答案:

没有答案