I deploy my Angular application to Heroku, with Node.js as the backend. However, when I deploy to Heroku, the static files page works fine. The page that needs data from backend is infinitely loading.
This is my Github link: https://github.com/JNUGroup/COVID-19_heroku
my index.js as the server file like this:
const port = process.env.PORT || 3001;
app.use(express.static(__dirname + '/dist/covid19-tracker'));
app.get('/*', function(req, res){
res.sendFile(path.join(__dirname + '/dist/covid19-tracker/index.html'));
});
app.set('port',port);
app.listen(port, () => {
console.log(`Listening on port:${port}`);
});
my package.json look like this:
{
"name": "covid19-tracker",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "node index.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"heroku-postbuild": "ng build --prod"
},
"private": true,
"dependencies": {
"#angular/animations": "~9.1.0",
"#angular/cli": "~9.1.0",
"#angular/common": "~9.1.0",
"#angular/compiler": "~9.1.0",
"#angular/compiler-cli": "~9.1.0",
"#angular/core": "~9.1.0",
"#angular/forms": "~9.1.0",
"#angular/platform-browser": "~9.1.0",
"#angular/platform-browser-dynamic": "~9.1.0",
"#angular/router": "~9.1.0",
"chart.js": "^2.9.3",
"enhanced-resolve": "^4.1.1",
"express": "^4.17.1",
"leaflet": "^1.6.0",
"locutus": "^2.0.11",
"mocha": "^7.1.2",
"ng2-google-charts": "^5.0.0",
"ngx-bootstrap": "^5.5.0",
"ngx-spinner": "^9.0.2",
"ngx-toastr": "^12.0.1",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"typescript": "~3.8.3",
"zone.js": "~0.10.2",
"cors": "^2.8.5",
"cross-fetch": "^3.0.4",
"node-fetch": "^2.6.0",
"nodemailer": "^6.4.6",
"novelcovid": "^1.1.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.901.0",
"#angular/language-service": "~9.1.0",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^5.0.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0"
},
"engines": {
"node": "12.16.1",
"npm": "6.13.4"
}
}
and all the build is successful. It just cannot read data from backend. I cannot figure it out, hope anyone could give me some suggestion.
Related
I'm building an app using Ionic 6.19.0 and it suddenly started to face building issues.
I get Error: spawn UNKNOWN each time I execute ionic serve.
This is my package.json file
{
"name": "stile",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular-devkit/schematics": "^13.3.3",
"#angular/common": "~13.0.0",
"#angular/core": "~13.0.0",
"#angular/forms": "~13.0.0",
"#angular/platform-browser": "~13.0.0",
"#angular/platform-browser-dynamic": "~13.0.0",
"#angular/router": "~13.0.0",
"#auth0/angular-jwt": "^5.0.2",
"#capacitor/android": "3.4.3",
"#capacitor/app": "1.1.0",
"#capacitor/camera": "^1.3.1",
"#capacitor/core": "3.4.0",
"#capacitor/haptics": "1.1.4",
"#capacitor/keyboard": "1.2.1",
"#capacitor/status-bar": "1.0.7",
"#ionic/angular": "^6.0.0",
"#npmcli/node-gyp": "^2.0.0",
"bootstrap": "^5.1.3",
"install": "^0.13.0",
"jquery": "^3.6.0",
"json-server": "^0.17.0",
"node-sass": "^7.0.1",
"npm": "^8.6.0",
"rxjs": "~6.6.0",
"tslib": "^2.3.1",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "^13.3.3",
"#angular-eslint/builder": "^12.2.1",
"#angular-eslint/eslint-plugin": "~13.0.1",
"#angular-eslint/eslint-plugin-template": "~13.0.1",
"#angular-eslint/template-parser": "~13.0.1",
"#angular/cli": "~13.0.1",
"#angular/compiler": "~13.0.0",
"#angular/compiler-cli": "~13.0.0",
"#angular/language-service": "~13.0.0",
"#capacitor/cli": "3.4.0",
"#ionic/angular-toolkit": "^6.1.0",
"#popperjs/core": "^2.11.5",
"#types/jasmine": "~3.6.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"#typescript-eslint/eslint-plugin": "5.3.0",
"#typescript-eslint/parser": "5.3.0",
"acorn": "^8.7.0",
"ajv": "^6.12.6",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "~3.8.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"typescript": "~4.4.4"
},
"description": "An Ionic project"
}
Here are few solutions that might help:
Ensure you're in the root folder of your project.
Try fixing the existing node_modules folder with npm rebuild + reassign
permissions to your node_modules folder: chmod 755 -R
/path/to/node_modules
Remove node_modules and reinstall with npm install
I have a angular ( 9 ) project.
node --version : v12.16.1
npm --version : 6.14.5
When I try to build using "npm install" i get error
Schema validation failed with the following errors:
Data path ".builders['app-shell']" should have required property 'class'.
The package.json file is given here
{
"name": "my-app",
"version": "1.1.1",
"scripts": {
"ng": "ng",
"start:dev": "ng serve --configuration=dev",
"start": "node server.js",
"build": "ng build --aot --prod --configuration=production",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "npm run build"
},
"private": true,
"dependencies": {
"#angular/animations": "^7.2.4",
"#angular/cdk": "~7.3.2",
"#angular/cli": "^7.3.1",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/forms": "~7.2.0",
"#angular/material": "^7.3.2",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"#types/chart.js": "^2.7.45",
"angular4-hal": "^7.8.2",
"chart.js": "^2.7.3",
"core-js": "^2.5.4",
"express": "^4.16.4",
"hammerjs": "^2.0.8",
"moment": "^2.24.0",
"ngx-json-viewer": "^2.4.0",
"path": "^0.12.7",
"primeflex": "^1.0.0-rc.1",
"primeicons": "^1.0.0",
"primeng": "^7.1.0",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"typescript": "~3.2.2",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.901.1",
"#angular/compiler-cli": "^9.1.1",
"#angular/language-service": "~7.2.0",
"#types/jasmine": "~2.8.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^8.9.5",
"codelyzer": "~4.5.0",
"enhanced-resolve": "^3.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^5.0.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": "8.11.3",
"npm": "6.8.0"
}
}
I am trying to build macOs app using electron by running electron-packager . --platform=darwin
It creates an app but when i run it gives me following error
Uncaught Exception:
Error: Cannot find module '/Users/msaadbashir/Downloads/Angular/accounting/accounting-darwin-x64/accounting.app/Contents/Resources/app/main.js'
at Module._resolveFilename (internal/modules/cjs/loader.js:797:17)
at Function../lib/common/reset-search-paths.ts.Module._resolveFilename (electron/js2c/browser_init.js:7736:16)
at Object.<anonymous> (electron/js2c/browser_init.js:6116:37)
at Object../lib/browser/init.ts (electron/js2c/browser_init.js:6124:30)
at __webpack_require__ (electron/js2c/browser_init.js:20:30)
at electron/js2c/browser_init.js:84:18
at electron/js2c/browser_init.js:87:10
at NativeModule.compile (internal/bootstrap/loaders.js:287:5)
at NativeModule.compileForPublicLoader (internal/bootstrap/loaders.js:222:8)
at loadNativeModule (internal/modules/cjs/helpers.js:23:9)
I have done the following apart from installing electron.
index.html <base href="./">
main.js
const { app, BrowserWindow } = require('electron')
let win;
function createWindow() {
win = new BrowserWindow({
width: 600,
height: 600,
backgroundColor: '#ffffff',
})
win.loadFile('./dist/accounting/index.html')
win.on('closed',function() {
win = null
})
}
app.on('ready',createWindow)
app.on('window-all-closed',function() {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate',function() {
if (win === null) {
createWindow()
}
})
package.json
{
"name": "accounting",
"version": "0.0.0",
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build": "ng build --prod"
},
"private": true,
"dependencies": {
"#angular/animations": "~9.0.6",
"#angular/cdk": "^9.2.4",
"#angular/common": "~9.0.6",
"#angular/compiler": "~9.0.6",
"#angular/core": "~9.0.6",
"#angular/forms": "~9.0.6",
"#angular/localize": "~9.0.6",
"#angular/material": "^9.2.4",
"#angular/platform-browser": "~9.0.6",
"#angular/platform-browser-dynamic": "~9.0.6",
"#angular/router": "~9.0.6",
"#ng-bootstrap/ng-bootstrap": "^6.1.0",
"#ng-select/ng-select": "^4.0.0",
"#ngx-loading-bar/core": "^4.2.0",
"#ngx-loading-bar/http-client": "^4.2.0",
"#ngx-loading-bar/router": "^4.2.0",
"bootstrap": "^4.5.0",
"e-ngx-print": "^5.3.1",
"html2canvas": "^1.0.0-rc.5",
"html2pdf.js": "^0.9.2",
"jquery": "^3.5.1",
"jspdf": "^1.5.3",
"ng2-date-picker": "^9.0.0",
"ngx-bootstrap": "^5.6.1",
"ngx-infinite-scroll": "^9.0.0",
"ngx-mask": "^9.0.2",
"ngx-toastr": "^12.0.1",
"rxjs": "^6.5.5",
"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/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"electron": "^9.0.0",
"electron-packager": "^14.2.1",
"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"
}
}
You need:
set base-href to the root folder npm run electron-build -- --base-href ./
be sure the main.js in the root
be sure that in package.json main field refers to correct path of main.js
I am a beginner to the MEAN stack framework. I am trying to run a node js server, using "nodemon server.js" command. But I get this error. I am trying to figure out why
Angular CLI: 9.1.3
Node: 12.4.0
Angular: 9.1.3
This is my package.json file
{
"name": "Angular-App",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"start:server": "nodemon server.js"
},
"private": true,
"dependencies": {
"#angular/animations": "^9.1.3",
"#angular/common": "^9.1.3",
"#angular/compiler": "^9.1.3",
"#angular/core": "^9.1.3",
"#angular/fire": "^6.0.0",
"#angular/forms": "^9.1.3",
"#angular/platform-browser": "^9.1.3",
"#angular/platform-browser-dynamic": "^9.1.3",
"#angular/router": "^9.1.3",
"bootstrap": "^4.4.1",
"core-js": "^3.6.5",
"express": "^4.17.1",
"firebase": "^7.14.2",
"jquery": "^3.5.0",
"ngx-bootstrap": "^5.6.1",
"rxjs": "~6.5.5",
"tslib": "^1.10.0",
"zone.js": "~0.10.3"
},
"devDependencies": {
"#angular-devkit/build-angular": "^0.901.3",
"#angular/cli": "^9.1.3",
"#angular/compiler-cli": "^9.1.3",
"#angular/language-service": "^9.1.3",
"#types/jasmine": "~3.3.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"nodemon": "^2.0.3",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "^3.8.3"
}
}
These are my versions
Please help, I am stuck in my project here
I am trying to deploy angular app on Heroku server with the following method.
https://medium.com/#hellotunmbi/how-to-deploy-angular-application-to-heroku-1d56e09c5147
If any one have idea about this, please help me as I am trying to go to root of this error. Thanks in Advance
I changed to -prod to --prod and that helped me to deploy the app successfully, however, while opening the app it gives me "" not found error "" and console error is Failed to load resource: the server responded with a status of 404 (Not Found).
here is the link for the app
https://recipebook-angularapp.herokuapp.com/
This app works perfectly on my local server.
Here is my package.json
{
"name": "recipe-book",
"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": "~7.2.0",
"#angular/cli": "~7.2.2",
"#angular/common": "~7.2.0",
"#angular/compiler": "~7.2.0",
"#angular/compiler-cli": "~7.2.0",
"#angular/core": "~7.2.0",
"#angular/forms": "~7.2.0",
"#angular/platform-browser": "~7.2.0",
"#angular/platform-browser-dynamic": "~7.2.0",
"#angular/router": "~7.2.0",
"bootstrap": "^3.4.0",
"core-js": "^2.5.4",
"express": "^4.16.4",
"path": "^0.12.7",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"typescript": "~3.2.2",
"zone.js": "~0.8.26"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.12.0",
"#angular/cli": "~7.2.2",
"#angular/compiler-cli": "~7.2.0",
"#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",
"enhanced-resolve": "^3.3.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",
"typescript": "~3.2.2"
},
"engines": {
"node": "11.6.0",
"npm": "6.5.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('./dist/recipe-book'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname,'/dist/recipe-book/index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8080);