getting error "The serve command requires to be run in an Angular project, but a project definition could not be found."
Below is my 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"
}
}
and 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);
the server.js file is in root directory. I followed this post to deploy a dummy app to heroku https://medium.com/@hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147
Seems like your project doesn't have angular.json
file present in your folder.
The post covered deployment for "@angular/cli": "^1.4.9"
which is old and used to generate angular-cli.json
file, which is not used anymore.
If you want to migrate from old angular-cli version to new one, then you can run the following command:
ng update @angular/cli --migrate-only --from=1.4.9
where --from
refers to your current version of angular-cli. Doing so, will take care of all the conversion and necessary files.
Reference: https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036