Heroku seems to build client but I see no dist folder - node.js

When pushing my angular/node app to heroku it seems to build successfully when I look at the logs. But I can see no dist folder being created in the angular side.
I built the angular client locally to make sure there were no errors in the code.
I have changed the build script from -
"postinstall": "ng build --prod"
which was throwing "path to environment.prod.ts could not be found" error to
"heroku-postbuild": "ng build --configuration=production"
which doest throw errors but doesn't continue to create the dist folder. So I am stuck right a bit.
angular package.json
{
"name": "client",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node app.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"heroku-postbuild": "ng build --configuration=production"
},
"private": true,
"dependencies": {
"#angular/cli": "~7.3.1",
"#angular/compiler-cli": "~7.2.0",
"typescript": "~3.2.2",
"#angular/animations": "^7.2.8",
"#angular/cdk": "^7.3.3",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/flex-layout": "^7.0.0-beta.24",
"#angular/forms": "~7.2.0",
"#angular/material": "^7.3.3",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"#vguleaev/angular-material-autocomplete": "0.0.10",
"#w11k/ngx-componentdestroyed": "^4.1.4",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"rxjs-observable-store": "^1.0.1",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.13.9",
"#angular/language-service": "~7.2.0",
"#types/jasmine": "~2.8.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0"
},
"engines": {
"node": "10.0.0",
"npm": "5.6.0"
}
}
node package.json
{
"name": "spotify-alias",
"version": "1.0.0",
"description": "",
"main": "app.js",
"engines": {
"node": "10.0.0",
"npm": "5.6.0"
},
"dependencies": {
"#babel/cli": "^7.5.5",
"#babel/core": "^7.5.5",
"#babel/node": "^7.5.0",
"#babel/preset-env": "^7.5.0",
"axios": "^0.19.0",
"concurrently": "^4.1.0",
"cookie-session": "^1.3.3",
"cors": "^2.8.5",
"express": "^4.16.4",
"mongoose": "^5.4.14",
"node-fetch": "^2.3.0",
"passport": "^0.4.0",
"passport-spotify": "^1.0.1"
},
"devDependencies": {
"nodemon": "^1.19.1"
},
"scripts": {
"start": "node app.js",
"server": "nodemon --exec babel-node app.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false && npm install --prefix client"
},
"author": "",
"license": "ISC"
}
app.js - node
if(process.env.NODE_ENV === 'production') {
app.use(express.static('/client/dist/index.html'));
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "dist", "index.html"));
});
}
I would like everything to build and the dist folder to be created. This is my first node app so please bear with me, there might be things that look completely off.
Like I am not 100% sure about the app.js code that resolves the path. I do know that /client is where the angular stuff is from root.
Any help much appreciated.

You do not have a build script. I see that you're using Babel. Thus, you need to tell Babel to run a build for you; which ultimately provides the dist folder (could be any name though).
"build": "babel src --out-dir dist --copy-files",

Do follow the blog to deploy angular apps on heroku
https://medium.com/#hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147

Related

Could not find the '#angular-devkit/build-angular:browser' builder's node package [duplicate]

This question already has answers here:
Angular 6 - Could not find module "#angular-devkit/build-angular"
(47 answers)
Closed 8 months ago.
I'm trying to deploy my app to heroku. Heroku local web works completely fine. I've tried adding npm i #angular-devkit/build-angular but it doesn't help and I also couldn't find anything similar on the internet. Deploying to Heroku works fine until it gets to ng build --prod command which can be found in "postinstall" inside angular package.json.
package.json
{
"name": "web",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"heroku-postbuild": "npm install && cd public && npm install #angular/cli -g && npm install",
"heroku-cleanup": "cd ./public && patch-package"
},
"dependencies": {
"#swimlane/ngx-charts": "^19.2.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"morgan": "~1.9.1",
"patch-package": "^6.4.7",
"pg": "^8.7.1"
},
"engines": {
"node": "16.10",
"npm": "7.24.0"
}
}
angular package.json
{
"name": "public",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "./node_modules/.bin/patch-package && ng build --prod --aot",
"heroku-cleanup": "./node_modules/.bin/patch-package"
},
"private": true,
"dependencies": {
"#angular/animations": "~11.2.12",
"#angular/common": "~11.2.12",
"#angular/compiler": "~11.2.12",
"#angular/core": "~11.2.12",
"#angular/forms": "~11.2.12",
"#angular/material": "^11.2.12",
"#angular/platform-browser": "~11.2.12",
"#angular/platform-browser-dynamic": "~11.2.12",
"#angular/router": "~11.2.12",
"#swimlane/ngx-charts": "^19.2.0",
"patch-package": "^6.4.7",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"typescript": "~4.1.5",
"zone.js": "~0.11.3"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.1102.11",
"#angular/cli": "~11.2.11",
"#angular/compiler-cli": "~11.2.12",
"#angular/cdk": "~11.2.11",
"#types/jasmine": "~3.6.0",
"#types/jquery": "^3.5.11",
"#types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0"
}
}
Procfile:
web: npm start
One thing to try is to re-install the package:
npm uninstall #angular-devkit/build-angular
npm install --save-dev #angular-devkit/build-angular
If that does not work, you can try:
ng update #angular/cli #angular/core --allow-dirty --force

dependencies in the wrong place with yarn

When I do yarn install && yarn workspace frontend install && yarn workspace backend install in my Typescript project (various package.json files below) the dependencies for (e.g.) Angular and CDK are all in the root node_modules folder, but when I run (e.g.) yarn workspace frontend ng build, I get An unhandled exception occurred: ENOENT: no such file or directory, lstat '/work/frontend/node_modules/#angular'. How do I get the dependencies in the right place?
Root package.json:
"name": "load-tester",
"version": "1.0.0",
"private": true,
"workspaces": [
"backend",
"frontend"
],
"scripts": {
"deploy": "yarn workspace frontend ng build && yarn workspace backend deploy"
},
"packageManager": "yarn#3.1.0",
"dependencies": {
"#aws-sdk/client-ec2": "^3.34.0",
"#aws-sdk/client-elastic-load-balancing-v2": "^3.34.0",
"#middy/http-content-negotiation": "^2.5.1",
"esbuild": "^0.12.28"
}
}
frontend/package.json
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"#angular/animations": "~12.2.0",
"#angular/cdk": "12.2.6",
"#angular/common": "~12.2.0",
"#angular/compiler": "~12.2.0",
"#angular/core": "~12.2.0",
"#angular/forms": "~12.2.0",
"#angular/material": "~12.2.6",
"#angular/platform-browser": "~12.2.0",
"#angular/platform-browser-dynamic": "~12.2.0",
"#angular/router": "~12.2.0",
"#aws-sdk/client-sns": "^3.34.0",
"#okta/okta-angular": "^4.1.0",
"#okta/okta-auth-js": "^5.6.0",
"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "~12.2.5",
"#angular/cli": "~12.2.5",
"#angular/compiler-cli": "~12.2.0",
"#angular/localize": "^12.2.5",
"#types/jasmine": "~3.8.0",
"#types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.3.5"
}
}
backend/package.json
{
"name": "backend",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",
"deploy": "yarn build && yarn cdk deploy"
},
"devDependencies": {
"#aws-cdk/assert": "^1.121.0",
"#aws-cdk/aws-apigateway": "1.121.0",
"#aws-cdk/aws-apigatewayv2": "1.121.0",
"#aws-cdk/aws-apigatewayv2-integrations": "1.121.0",
"#aws-cdk/aws-certificatemanager": "1.121.0",
"#aws-cdk/aws-dynamodb": "1.121.0",
"#aws-cdk/aws-ecs": "^1.121.0",
"#aws-cdk/aws-ecs-patterns": "^1.121.0",
"#aws-cdk/aws-lambda": "1.121.0",
"#aws-cdk/aws-lambda-event-sources": "1.121.0",
"#aws-cdk/aws-lambda-nodejs": "1.121.0",
"#aws-cdk/aws-logs": "1.121.0",
"#aws-cdk/aws-s3-deployment": "1.121.0",
"#aws-cdk/aws-sqs": "^1.121.0",
"#aws-solutions-constructs/aws-cloudfront-s3": "1.121.0",
"#types/aws-lambda": "^8.10.83",
"#types/http-errors": "^1.8.1",
"#types/jest": "^27.0.1",
"#types/node": "^16.9.6",
"#types/source-map-support": "^0.5.4",
"aws-cdk": "^1.121.0",
"eslint": "^7.32.0",
"jest": "^27.2.0",
"json-schema-to-ts": "^1.6.4",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
},
"dependencies": {
"#aws-cdk/aws-apigatewayv2-authorizers": "^1.130.0",
"#aws-cdk/cloud-assembly-schema": "^1.121.0",
"#aws-cdk/core": "^1.121.0",
"#aws-cdk/cx-api": "^1.121.0",
"#aws-cdk/region-info": "^1.121.0",
"#aws-sdk/client-dynamodb": "^3.34.0",
"#aws-sdk/client-ecs": "^3.34.0",
"#aws-sdk/client-elastic-load-balancing-v2": "^3.34.0",
"#aws-sdk/client-route-53": "^3.34.0",
"#aws-sdk/client-s3": "^3.34.0",
"#aws-sdk/client-sqs": "^3.34.0",
"#aws-sdk/lib-dynamodb": "^3.34.0",
"#aws-sdk/signature-v4-crt": "^3.34.0",
"#dazn/lambda-powertools-logger": "^1.28.1",
"#dazn/lambda-powertools-pattern-basic": "^1.29.0",
"#middy/core": "^2.5.1",
"#middy/http-cors": "^2.5.1",
"#middy/http-error-handler": "^2.5.1",
"#middy/http-json-body-parser": "^2.5.1",
"#middy/http-multipart-body-parser": "^2.5.1",
"#middy/sqs-json-body-parser": "^2.5.1",
"#middy/validator": "^2.5.1",
"#okta/jwt-verifier": "^2.3.0",
"ajv": "^8.6.3",
"aws-lambda": "^1.0.6",
"constructs": "^3.2.0",
"exponential-backoff": "^3.1.0",
"http-errors": "^1.8.0",
"middy-jsonapi": "2.0.1",
"source-map-support": "^0.5.16"
}
}
The problem turned out to have been my angular.json; in particular anywhere referring to ./node_modules/#angular. When I changed that to ../node_modules/#angular I was able to successfully build both frontend and backend.

Why am I getting an ng not found error when deploying my Angular project to Heroku?

My project layout looks like this:
package.json (A)
index.js
client
> package.json (B)
with my outer package.json (A) looking like this :
{
"name": "---",
"version": "1.0.0",
"description": "---",
"main": "index.js",
"scripts": {
"start": "node index.js",
"build": "cd client && ng build --prod && cd .. && node index.js"
},
"repository": {
"type": "git",
"url": "---"
},
"author": "---",
"license": "ISC",
"bugs": {
"url": "---"
},
"homepage": "---",
"dependencies": {
"axios": "^0.19.2",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.9.14"
}
}
while the package.json (B) inside the client folder that holds the angular project looks like this:
{
"name": "client",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/cli": "~9.0.6",
"#angular/compiler-cli": "~9.0.6",
"#angular/animations": "~9.0.6",
"#angular/common": "~9.0.6",
"#angular/compiler": "~9.0.6",
"#angular/core": "~9.0.6",
"#angular/fire": "^6.0.0",
"#angular/forms": "~9.0.6",
"#angular/platform-browser": "~9.0.6",
"#angular/platform-browser-dynamic": "~9.0.6",
"#angular/router": "~9.0.6",
"firebase": "^7.14.4",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.900.6",
"#angular/cli": "~9.0.6",
"#angular/compiler-cli": "~9.0.6",
"#angular/language-service": "~9.0.6",
"#types/node": "^12.11.1",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
}
Looking up other threads that have asked similar things, most of them said that I needed to move the #angular/cli and #angular/compiler-cli from devDependencies to dependencies, which is what I did.
However, when Heroku runs the script
"build": "cd client && ng build --prod && cd .. && node index.js"
I'm not sure why I keep getting the error that ng was not found. Another thing I tried was to add the preinstall script to package.json (A)
"preinstall": "npm install -g angular-cli"
which removed the ng not found error, but instead I got an error saying that the build command would only work inside of an angular-cli project, which is making me think that maybe the change directory isn't working? This is really confusing to me, because npm run build works fine for me...
I messed around a bit and finally got it to work. My solution was to change my package.json (A) scripts to
"scripts": {
"start": "node index.js",
"build": "cd client && npm install && npm run build --prod"
},
and to move literally everything in devDependencies in package.json (B) into the dependencies folder.

heroku/node deployment - cannot find module 'app/dist/server/app.js'

I've recently upgraded my angular2 app to angular 5 and I am having trouble deploying it to heroku where it used to work beforehand.
The issue here is that I have a Procfile that has this: 'web: node dist/server/app.js' - where the launch file is stored but heroku is trying to find it add this path - 'app/dist/server/app.js' I'm not sure where this /app is getting appended but it is causing the issue.
Cheers
error description
{
"name": "",
"version": "4.2.4",
"license": "",
"author": "",
"description": "",
"angular-cli": {},
"engines": {
"node": "8.9.4",
"npm": "5.6.0"
},
"scripts": {
"ng": "ng",
"build": "ng build --prod",
"start": "node dist/server/app.js",
"predev": "tsc -p server",
"dev": "node ./node_modules/mongodb-migrate -runmm -dbn dbSettings up && concurrently \"mongod\" \"ng serve -pc proxy.conf.json --open\" \"tsc -w -p server\" \"nodemon dist/server/app.js\"",
"prod": "concurrently \"mongod\" \"ng build -aot -prod && tsc -p server && node dist/server/app.js\"",
"test": "ng test",
"testbe": "tsc -p server && mocha dist/server/test --exit",
"lint": "ng lint",
"lintbe": "tslint server/**/**.ts{,x}",
"e2e": "ng e2e",
"migrations": "node ./node_modules/mongodb-migrate -runmm -dbn dbSettings up",
"create-migration": "node ./node_modules/mongodb-migrate -runmm create"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.0",
"#angular/cdk": "2.0.0-beta.12",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/material": "2.0.0-beta.12",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"#sendgrid/mail": "^6.2.1",
"angular-bootstrap-md": "^5.1.2",
"angular2-jwt": "^0.2.3",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"bootstrap": "4.0.0-alpha.5",
"cheerio": "^1.0.0-rc.2",
"core-js": "^2.4.1",
"cron": "^1.3.0",
"dotenv": "^4.0.0",
"express": "^4.16.3",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"jquery": "^3.3.1",
"jsonwebtoken": "^8.2.1",
"migrate-mongo": "^2.2.1",
"moment": "^2.20.1",
"mongodb-migrate": "^2.0.2",
"mongoose": "^5.0.13",
"morgan": "^1.9.0",
"popper.js": "^1.14.3",
"npm-check": "^5.6.0",
"redis": "^2.8.0",
"request": "^2.85.0",
"rxjs": "^5.5.6",
"tether": "1.4.0",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "~1.7.3",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "^2.8.6",
"#types/jasminewd2": "~2.0.2",
"#types/node": "~6.0.60",
"chai": "^4.1.2",
"chai-http": "^4.0.0",
"codelyzer": "~4.0.1",
"concurrently": "^3.5.1",
"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",
"mocha": "^5.0.5",
"nodemon": "^1.17.3",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
I once came across with a similar issue with a nodejs typescript application that I had connected with git. The .gitingnore file omits js files. So when heroku takes a pull from git it only obtains typescript script(no js files). Where as the npm start script refers to js files.
Another thing to note it that heroku runs only two commands
npm install
and
npm start
Solution
Add ng build into the start script so that production files are available for heroku.
package.json
"ng": "ng",
"build": "ng build --prod",
"start": "ng build --prod && node dist/server/app.js",

Error in package.json deploying Angular2 project on Azure using bitbucket

I am facing a issue deploying angular2 app on azure. I get an error on following line
"engines":{"node":"6.2.1"},
I have given this version as WEBSITE_NODE_DEFAULT_VERSION has the value 6.2.1. Anyone having idea about this then please share.
Here is the error snapshot:
package.json looks as follows:
{
"name": "angular-quickstart",
"version": "1.0.0",
"engines":{"node":"6.2.1"},
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"docker-build": "docker build -t ng2-quickstart .",
"docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
"pree2e": "npm run webdriver:update",
"e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
"lint": "tslint ./app/*/.ts -t verbose",
"lite": "node_modules\.bin\lite-server",
"postinstall": "typings install",
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
"test-once": "tsc && karma start karma.conf.js --single-run",
"tsc": "node_modules\.bin\tsc",
"concurrently": "node_modules\.bin\concurrently",
"tsc:w": "node_modules\.bin\tsc -w",
"typings": "node_modules\.bin\typings",
"webdriver:update": "webdriver-manager update"
},
"keywords": [],
"author": "",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/angular/angular.io/blob/master/LICENSE"
}
],
"dependencies": {
"#angular/common": "~2.1.0",
"#angular/compiler": "~2.1.0",
"#angular/core": "~2.1.0",
"#angular/forms": "~2.1.0",
"#angular/http": "~2.1.0",
"#angular/platform-browser": "~2.1.0",
"#angular/platform-browser-dynamic": "~2.1.0",
"#angular/router": "~3.1.0",
"#angular/upgrade": "~2.1.0",
"angular-in-memory-web-api": "~0.1.5",
"bootstrap": "^3.3.7",
"systemjs": "0.19.39",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"zone.js": "^0.6.25",
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings": "^1.4.0"
},
"devDependencies": {
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings": "^1.4.0",
"canonical-path": "0.0.2",
"http-server": "^0.9.0",
"tslint": "^3.15.1",
"lodash": "^4.16.2",
"jasmine-core": "~2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-htmlfile-reporter": "^0.3.4",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^3.3.0",
"rimraf": "^2.5.4"
},
"repository": {}
}
Please suggest a solution.
When you deploy your app in a server or a cloud, you should run it on a port provided with process.env.PORT, here is an example:
app.listen(process.env.PORT || 3000, () => {
console.log('Example app is running!');
});
in your package.json file the start script is setting the app to run on port 3000 by default.
From Angular js2 Documentary:
If Node.js and npm aren't already on your machine, install them. Our examples require node v4.x.x or higher and npm 3.x.x or higher. To check which version you are using, run node -v and npm -v in a terminal window.
Could you please check your npm version?

Resources