得到错误“ serve命令需要在Angular项目中运行,但是找不到项目定义。”
下面是我的package.json。
{
"name": "demo-deploy",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot -prod"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/cli": "^7.2.3",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/compiler-cli": "^5.2.11",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"express": "^4.16.4",
"path": "^0.12.7",
"rxjs": "^5.5.6",
"typescript": "~2.5.3",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^7.2.3",
"@angular/compiler-cli": "^5.2.11",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"enhanced-resolve": "^3.3.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
},
"engines": {
"node": "8.9.4",
"npm": "5.6.0"
}
}
和server.js
//Install express server
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static(__dirname + '/dist/'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);
server.js文件位于根目录中。 我按照这篇文章将虚拟应用程序部署到heroku https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147
答案 0 :(得分:0)
似乎您的项目中的文件夹中没有angular.json
文件。
该帖子介绍了"@angular/cli": "^1.4.9"
的旧部署,该部署用于生成angular-cli.json
文件,该文件已不再使用。
如果要从旧的angular-cli版本迁移到新版本,则可以运行以下命令:
ng update @angular/cli --migrate-only --from=1.4.9
其中--from
是指您当前的angular-cli版本。这样做将处理所有转换和必要的文件。
参考: https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036
答案 1 :(得分:0)
我的问题完全是在部署到 Heroku 之后。我的应用在其他任何地方都运行良好。
只需从 build
中删除 package.json
命令。或者,如果您确实希望远程构建它,请进行修改以使其更准确。