[英]Application error after succeeded Heroku Build (Node + React App)
[英]Node app build succeeded but not showing up on Heroku (MEAN Stack app)
我正在將我的應用程序部署到 Heroku,經過幾次失敗的構建嘗試后,它最終成功構建,但是當我想訪問該應用程序時,它給了我“應用程序錯誤”。 這是成功的構建日志:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 10.16.3
engines.npm (package.json): 6.11.3
Resolving node version 10.16.3...
Downloading and installing node 10.16.3...
Bootstrapping npm 6.11.3 (replacing 6.9.0)...
npm 6.11.3 installed
-----> Restoring cache
Cached directories were not restored due to a change in version of node, npm, yarn or stack
Module installation may take longer for this build
-----> Installing dependencies
Installing node modules
> fsevents@1.2.11 install /tmp/build_b07ba6f8_/node_modules/fsevents
> node-gyp rebuild
make: Entering directory '/tmp/build_b07ba6f8_/node_modules/fsevents/build'
SOLINK_MODULE(target) Release/obj.target/.node
COPY Release/.node
make: Leaving directory '/tmp/build_b07ba6f8_/node_modules/fsevents/build'
> core-js@2.6.11 postinstall /tmp/build_b07ba6f8_/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
> core-js@3.2.1 postinstall /tmp/build_b07ba6f8_/node_modules/@angular-devkit/build-
angular/node_modules/core-js
> node scripts/postinstall || echo "ignore"
> bcrypt@3.0.7 install /tmp/build_b07ba6f8_/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
[bcrypt] Success: "/tmp/build_b07ba6f8_/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is
installed via remote
> @angular/cli@8.3.23 postinstall /tmp/build_b07ba6f8_/node_modules/@angular/cli
> node ./bin/postinstall/script.js
added 1056 packages in 24.037s
-----> Build
-----> Caching build
- node_modules
-----> Pruning devDependencies
removed 496 packages and audited 628 packages in 11.836s
found 132 vulnerabilities (131 low, 1 moderate)
run `npm audit fix` to fix them, or `npm audit` for details
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 54.9M
-----> Launching...
Released v9
然后當我看到我無法訪問我的網絡應用程序時,日志顯示:
2020-09-29T20:34:29.157236+00:00 app[web.1]: npm ERR! meanstacknieuw@1.0.0 start: node index.js
2020-09-29T20:34:29.157459+00:00 app[web.1]: npm ERR! Exit status 1
2020-09-29T20:34:29.157845+00:00 app[web.1]: npm ERR!
2020-09-29T20:34:29.158095+00:00 app[web.1]: npm ERR! Failed at the meanstacknieuw@1.0.0 start
script.
2020-09-29T20:34:29.158322+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There
is likely additional logging output above.
2020-09-29T20:34:29.170467+00:00 app[web.1]:
2020-09-29T20:34:29.170778+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-09-29T20:34:29.171436+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-09-29T20_34_29_159Z-
debug.log
2020-09-29T20:34:29.256127+00:00 heroku[web.1]: Process exited with status 1
2020-09-29T20:34:29.304162+00:00 heroku[web.1]: State changed from starting to crashed
這是我的 package.json 文件:
` {
"name": "meanstacknieuw",
"version": "1.0.0",
"description": "refreshing",
"main": "index.js",
"engines": {
"node": "10.16.3",
"npm": "6.11.3"
},
"scripts": {
"ng": "ng",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/y0u-s/vf-app.git"
},
"keywords": [
"MEAN",
"stack",
"angular",
"2",
"application"
],
"author": "Youssef",
"license": "ISC",
"bugs": {
"url": "https://github.com/y0u-s/latest-mean-stack-app/issues"
},
"homepage": "https://github.com/y0u-s/latest-mean-stack-app#readme",
"dependencies": {
"@angular/cli": "^8.3.20",
"@angular/compiler": "^8.2.14",
"rxjs": "^6.3.3",
"@angular/core": "^7.2.16",
"@angular/compiler-cli": "^8.2.14",
"angular2-flash-messages": "^3.0.1",
"bcrypt": "^3.0.4",
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"file-extension": "^4.0.5",
"jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"node-localstorage": "^2.1.4",
"nodemailer": "^6.4.1",
"simple-odata-server": "^1.1.1",
"typescript": "~3.2.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.20"
}
}`
我的 server.js 文件:
const port = process.env.PORT || 8080;
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With,
Content-Type, Accept");
next();
});
app.use(cors({
origin: 'http://localhost:4200'
}));
app.get('*', function(req, res){
res.sendFile(path.join(__dirname + '/public/index.html'));
});
app.listen(port, () => {
console.log('Hello on port ' + port)
});
如果您需要更多上下文或代碼,請告訴我。
當 heroku 啟動你的應用程序時,它會運行npm run start
。 您的start
腳本指的是index.js
,而您指的是server.js
- 這是正確的嗎?
npm run start
在本地主機上正常工作嗎?
"scripts": {
"ng": "ng",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
}
在 server.js 中,檢查您的路徑是否與 dist/{folder_name} 匹配
{folder_name} 可以在 package.json 文件中配置。
例如在 package.json 文件中
{“名稱”:“文件夾名稱”,}
你需要指定heroku env的端口
app.listen( process.env.PORT || 8001, () => {
console.log("Server listening ...")
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.