gpt4 book ai didi

node.js - Heroku - 错误 : ENOENT: no such file or directory, 统计 '/app/dist/index.html'

转载 作者:太空宇宙 更新时间:2023-11-04 00:03:15 27 4
gpt4 key购买 nike

我正在尝试在 heroku 上部署我的 Angular 应用程序,但出现以下错误:

项目结构:

我的index.html位于src文件夹内

enter image description here

Heroku 日志:

2018-12-06T10:30:46.837610+00:00 heroku[web.1]: Starting process with command `npm start`
2018-12-06T10:30:50.434505+00:00 app[web.1]:
2018-12-06T10:30:50.434529+00:00 app[web.1]: > music-app@0.0.0 start /app
2018-12-06T10:30:50.434531+00:00 app[web.1]: > node server.js
2018-12-06T10:30:50.434532+00:00 app[web.1]:
2018-12-06T10:30:51.276734+00:00 heroku[web.1]: State changed from starting to up
2018-12-06T10:30:51.217887+00:00 app[web.1]: Server started running..
2018-12-06T10:30:51.000000+00:00 app[api]: Build succeeded
2018-12-06T10:31:05.060270+00:00 heroku[router]: at=info method=GET path="/" host=boulder-app.herokuapp.com request_id=69ed1cd2-fb68-499a-9568-bfb3af482188 fwd="115.112.65.146" dyno=web.1 connect=1ms service=58ms status=404 bytes=380 protocol=https
2018-12-06T10:31:05.049971+00:00 app[web.1]: Fetching from../app/dist/index.html
2018-12-06T10:31:05.060851+00:00 app[web.1]: Error: ENOENT: no such file or directory, stat '/app/dist/index.html'

我的 Package.json:

{
"name": "music-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot -prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"bootstrap": "^4.1.2",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26",
"@angular/cli": "~6.0.8",
"@angular/compiler-cli": "^6.0.3",
"typescript": "~2.7.2",
"express":"^4.15.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
},
"engines":{
"node":"~8.14.0",
"npm":"~5.0.0"
}
}

我的 server.js:

const express = require('express');
const app = express();
const path = require('path');

app.use(express.static(__dirname + '/dist'));
app.listen(process.env.PORT || 8080);

//PATH LOCATION STARTEGY

app.get('/*', function(req,res){
const fullPath = path.join(__dirname + '/dist/index.html');
console.log(" Fetching from.." + fullPath);
res.sendFile(fullPath);
})

console.log('Server started running..');

//Changed to run on Heroku

最佳答案

得到答案:

在 server.js 中,我必须将路径从 /dist 更改为 /dist/music-app 并且从 /dist/index.html/dist/music-app/index.html

其中,music-app 是我的 package.json 文件中的名称属性 ["name": "music-app"]。

关于node.js - Heroku - 错误 : ENOENT: no such file or directory, 统计 '/app/dist/index.html',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53649484/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com