We have an angular application that is deployed in a container, with an injected configuration file when starting (so not when building). We used to have it on Angular 7 (Node.js 10), and there we had no issues. We are currently in the process of upgrading to Angular 12 (Node.js 14), and are running into issues with our injected configuration file.
The configuration file is injected as assets/environments/environment.json, but in practice (due to the container system), environment.json is a symbolic link to assets/environments/.data/environment.json.
Now somewhere in the application, we try to get this file (through a regular HTTP call) to load our configuration. This http call works for http://<url>/assets/css/all.css, for example, but not for http://<url>/assets/environments/environment.json, seemingly because of the symbolic link.
What can we do to be able to HTTP get this file, hidden behind the symbolic link?
For completeness, our package.json:
{
"scripts": {
"start": "serve -s dist",
"build": "ng build --configuration production",
"serve": "ng serve --host 0.0.0.0",
"test": "ng test",
"lint": "ng lint"
},
"private": true,
"dependencies": {
"#angular/animations": "^12.1.0",
"#angular/cdk": "^12.1.0",
"#angular/cli": "^12.1.0",
"#angular/common": "^12.1.0",
"#angular/compiler": "^12.1.0",
"#angular/compiler-cli": "^12.1.0",
"#angular/core": "^12.1.0",
"#angular/forms": "^12.1.0",
"#angular/platform-browser": "^12.1.0",
"#angular/platform-browser-dynamic": "^12.1.0",
"#angular/router": "^12.1.0",
"#ngx-translate/core": "^13.0.0",
"#ngx-translate/http-loader": "^6.0.0",
"#popperjs/core": "^2.9.2",
"adal-angular": "^1.0.18",
"bootstrap": "^5.0.2",
"core-js": "^3.15.1",
"jquery": "^3.6.0",
"messageformat": "^2.3.0",
"ngx-translate-messageformat-compiler": "^4.10.0",
"popper.js": "^1.16.1",
"primeicons": "^4.1.0",
"primeng": "^12.0.0",
"process": "^0.11.10",
"rxjs": "^7.1.0",
"serve": "^12.0.0",
"tslib": "^2.3.0",
"util": "^0.12.4",
"zone.js": "^0.11.4"
},
"devDependencies": {
"#angular-builders/custom-webpack": "^12.1.0",
"#angular-devkit/build-angular": "^12.1.0",
"#angular/language-service": "^12.1.0",
"#types/adal-angular": "^1.0.1",
"#types/jasmine": "^3.7.7",
"#types/jasminewd2": "^2.0.9",
"#types/node": "^15.12.5",
"codelyzer": "^6.0.2",
"jasmine-core": "^3.7.1",
"jasmine-spec-reporter": "^7.0.0",
"karma": "^6.3.4",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^4.0.1",
"karma-jasmine-html-reporter": "^1.6.0",
"protractor": "^7.0.0",
"ts-node": "^10.0.0",
"tslint": "^5.11.0",
"typescript": "^4.3.4"
}
}
and our angular.json:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"application-name": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/",
"index": "src/index.html",
"main": "src/main.ts",
"preserveSymlinks": true,
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"./src/favicon.ico",
"./src/assets"
],
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./src/assets/css/all.css",
"./src/styles.css"
],
"scripts": [
"./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
"./node_modules/jquery/dist/jquery.slim.min.js",
"./node_modules/popper.js/dist/umd/popper.min.js"
]
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "application-name:build"
},
"configurations": {
"production": {
"browserTarget": "application-name:build:production"
}
}
}
}
}
}
}
Related
I have a library on angular 12 which when served, watches for changes and automatically triggers the build again. My script for automatically building the library is:
ng build library --watch.
The issue is after building successfully, the automatic build triggers every minute even when no changes are made to any file.
My package.json:
{
"name": "test-library",
"version": "1.0.0-1",
"scripts": {
"ver": "genversion --es6 --semi ./libs/ui/src/lib/version-number/version-number.model.ts",
"ng": "ng",
"serve": "ng build library --watch",
"build": "ng build library --configuration production",
"npm-publish": "node cleanPackage.js && npm publish dist"
},
"peerDependencies": {
"#agm/core": "^3.0.0-beta.0",
"core-js": "^3.16.2",
"date-fns": "2.23.0",
"hammerjs": "^2.0.8",
"ng2-validation": "^4.2.0",
"rxjs": "~6.5.2",
"#angular/animations": "^12.2.5",
"#angular/cdk": "^12.2.5",
"#angular/common": "~12.2.5",
"#angular/compiler": "~12.2.5",
"#angular/core": "~12.2.5",
"#angular/forms": "~12.2.5",
"#angular/material": "^12.2.5",
"#angular/material-moment-adapter": "^12.2.5",
"#angular/platform-browser": "~12.2.5",
"#angular/platform-browser-dynamic": "~12.2.5",
"#angular/router": "~12.2.5",
"#angular/service-worker": "~12.2.5",
"#ngrx/effects": "12.4.0",
"#ngrx/router-store": "12.4.0",
"#ngrx/store": "12.4.0",
"#ngrx/store-devtools": "12.4.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#agm/core": "^3.0.0-beta.0",
"#angular-devkit/build-angular": "~12.2.5",
"#angular/animations": "^12.2.5",
"#angular/cdk": "^12.2.5",
"#angular/cli": "~12.2.5",
"#angular/common": "~12.2.5",
"#angular/compiler": "~12.2.5",
"#angular/compiler-cli": "~12.2.5",
"#angular/core": "~12.2.5",
"#angular/forms": "~12.2.5",
"#angular/language-service": "~12.2.5",
"#angular/material": "^12.2.5",
"#angular/material-moment-adapter": "^12.2.5",
"#angular/platform-browser": "~12.2.5",
"#angular/platform-browser-dynamic": "~12.2.5",
"#angular/router": "~12.2.5",
"#angular/service-worker": "~12.2.5",
"#angularclass/hmr": "^3.0.0",
"#fortawesome/angular-fontawesome": "^0.8.2",
"#fortawesome/fontawesome-svg-core": "^1.2.36",
"#fortawesome/free-brands-svg-icons": "^5.15.4",
"#fortawesome/free-regular-svg-icons": "^5.15.4",
"#fortawesome/free-solid-svg-icons": "^5.15.4",
"#ks89/angular-modal-gallery": "^7.2.5",
"#ngrx/effects": "12.4.0",
"#ngrx/router-store": "12.4.0",
"#ngrx/store": "12.4.0",
"#ngrx/store-devtools": "12.4.0",
"#types/google-maps": "^3.2.0",
"#types/googlemaps": "3.39.13",
"#types/hammerjs": "^2.0.36",
"#types/jest": "25.1.4",
"#types/node": "^12.11.1",
"angular-cc-library": "^2.1.2",
"angular-svg-round-progressbar": "^6.0.1",
"chart.js": "^2.5.0",
"codelyzer": "^6.0.0",
"core-js": "^3.16.2",
"cypress": "^5.1.0",
"date-fns": "2.23.0",
"dotenv": "6.2.0",
"edit-json-file": "^1.6.0",
"genversion": "^2.2.1",
"hammerjs": "^2.0.8",
"jest": "^27.0.0",
"jest-preset-angular": "9.0.6",
"lodash.isequal": "4.5.0",
"mousetrap": "^1.6.5",
"ng-packagr": "^12.2.1",
"ng-samurai": "^2.0.6",
"ng2-charts": "^2.2.3",
"ng2-validation": "^4.2.0",
"prettier": "^2.0.4",
"rxjs": "~6.5.2",
"signature_pad": "^3.0.0-beta.4",
"ts-jest": "~27.0.5",
"ts-node": "~7.0.0",
"tslib": "^2.0.0",
"tslint": "~6.1.0",
"typescript": "~4.3.5",
"zone.js": "~0.11.4"
}
}
My angular.json:
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"projects": {
"web": {
"projectType": "library",
"root": "",
"sourceRoot": "src",
"prefix": "fin",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "tsconfig.lib.json",
"project": "ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js"
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.lib.json",
"tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "web",
"cli": {
"defaultCollection": "#nrwl/angular",
"analytics": false
},
"schematics": {
"#nrwl/angular:application": {
"unitTestRunner": "jest",
"e2eTestRunner": "cypress"
},
"#nrwl/angular:library": {
"unitTestRunner": "jest"
},
"#nrwl/angular:component": {
"styleext": "scss"
}
}
}
I have projects that use this library and when the library builds every minute it triggers a build on the project as well making it to reload. This is really tough especially when debugging things on the project. I don't know what's the issue here and any help is appreciated.
Please let me know if you need any additional info.
This question already has answers here:
Angular 6 many Can't resolve errors (crypto, fs, http, https, net, path, stream, tls, zlib)
(11 answers)
Closed 2 years ago.
I have created my Angular 8 application.
on command ng serve application running smoothly without any errors and code work properly but,
when I create a build for production then I got the error image shown below.
I use the node-rsa package to encrypted and decrypt my data but I'm not able to build a project for a production server, I don't know how these errors are raised.
My package.json
{
"name": "cftrack",
"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/animations": "~8.2.14",
"#angular/cdk": "~8.2.3",
"#angular/common": "~8.2.14",
"#angular/compiler": "~8.2.14",
"#angular/core": "~8.2.14",
"#angular/forms": "~8.2.14",
"#angular/material": "^8.2.3",
"#angular/material-moment-adapter": "^8.2.3",
"#angular/platform-browser": "~8.2.14",
"#angular/platform-browser-dynamic": "~8.2.14",
"#angular/router": "~8.2.14",
"#fortawesome/fontawesome-free": "^5.15.1",
"#types/jquery": "^3.5.4",
"angular-animations": "^0.11.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.3.1",
"bootstrap-select": "^1.13.18",
"buffer": "^6.0.3",
"classlist.js": "^1.1.20150312",
"cors": "^2.8.5",
"file-saver": "^2.0.5",
"font-awesome": "^4.7.0",
"fs": "0.0.1-security",
"jquery": "^3.5.1",
"moment": "^2.29.1",
"ngx-spinner": "^10.0.1",
"ngx-toastr": "^11.3.3",
"node-rsa": "^1.1.1",
"popper.js": "^1.16.1",
"primeng": "^11.0.0-rc.1",
"rxjs": "~6.4.0",
"tslib": "^1.10.0",
"uuid": "^8.3.2",
"web-animations-js": "^2.3.2",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.803.29",
"#angular/cli": "~8.3.29",
"#angular/compiler-cli": "~8.2.14",
"#angular/language-service": "~8.2.14",
"#types/jasmine": "~3.3.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^8.10.66",
"#types/node-rsa": "^1.0.0",
"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",
"protractor": "~7.0.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "^3.4.4"
},
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.3.29.",
"main": "karma.conf.js",
"author": "Sachin",
"license": "ISC"
}
My angular.json file
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"CFTRACK": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/CFTRACK",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/files",
"src/assets",
"src/web.config"
],
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/#fortawesome/fontawesome-free/css/v4-shims.min.css",
"node_modules/#fortawesome/fontawesome-free/css/all.min.css",
"node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",
"node_modules/ngx-toastr/toastr.css",
"node_modules/#angular/material/prebuilt-themes/indigo-pink.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.slim.min.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js",
"node_modules/bootstrap-select/dist/js/bootstrap-select.min.js"
]
},
"configurations": {
"production": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [{
"type": "initial",
"maximumWarning": "10mb",
"maximumError": "10mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "10kb",
"maximumError": "15kb"
}
]
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "CFTRACK:build"
},
"configurations": {
"production": {
"browserTarget": "CFTRACK:build:production"
}
}
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "CFTRACK:build"
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/files",
"src/assets",
"src/web.config"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "#angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "CFTRACK:serve"
},
"configurations": {
"production": {
"devServerTarget": "CFTRACK:serve:production"
}
}
}
}
}
},
"defaultProject": "CFTRACK"
}
After I enter the command "ng build --prod"
it raised error after 92% done like this
You mention
I have created my Angular 10 application
But package.json shows an angular 8 application ???
The first line of errors is: node-modules doesn't exist
Are You sure npm packages installed successfully?
Check it with npm install again.
Set aot flag in angular.json to true, to enable a head of time compilation.
serve the application again, you must see the problem.
For
Field 'browser' doesn't contain a valid alias configuration
error see this post
I found the answer to these related issues/bugs/errors,
by adding in package.json
"browser": {
"path": false,
"stream": false,
"tls": false,
"crypto": false,
"constants": false
}
more detail visit below mention almost the same error answer link https://stackoverflow.com/a/52367183/12213901
I've tried deploying my mean app to heroku, Angular 6. The deployment was successful without any errors but the page was blank.
my package.json file is:
{
"name": "koko-and-friend",
"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",
"preinstall": "npm install -g #angular/cli #angular/compiler-cli typescript #angular-devkit/build-angular"
},
"private": true,
"dependencies": {
"#angular/animations": "^6.0.2",
"#angular/common": "^6.0.2",
"#angular/compiler": "^6.0.2",
"#angular/core": "^6.0.2",
"#angular/forms": "^6.0.2",
"#angular/http": "^6.0.2",
"#angular/platform-browser": "^6.0.2",
"#angular/platform-browser-dynamic": "^6.0.2",
"#angular/router": "^6.0.2",
"bootstrap": "^4.1.1",
"core-js": "^2.5.4",
"express": "^4.16.3",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"popper.js": "^1.14.3",
"primeng": "^6.0.0-alpha.1",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#angular/compiler-cli": "^6.0.2",
"#angular-devkit/build-angular": "~0.6.3",
"typescript": "~2.7.2",
"#angular/cli": "~6.0.3",
"#angular/language-service": "^6.0.2",
"#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": "~1.4.2",
"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.11.2",
"npm": "6.0.1"
}
}
my server.js:
const path = require('path');
const express = require('express');
const app = express();
app.use(express.static(path.join(__dirname, '/dist')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/koko-and-friend/index.html'));
});
app.listen(process.env.PORT || 4201, () => {
console.log('Connected to Port'); //Listening on port 4201
});
my angular.json
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"koko-and-friend": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"#schematics/angular:component": {
"styleext": "sass"
}
},
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/koko-and-friend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"./src/assets/styles/bootstrap.min.css",
"./node_modules/font-awesome/css/font-awesome.min.css",
"./node_modules/primeng/resources/themes/omega/theme.css",
"src/styles.scss"
],
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/popper.js/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "koko-and-friend:build"
},
"configurations": {
"production": {
"browserTarget": "koko-and-friend:build:production"
}
}
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "koko-and-friend:build"
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.sass"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"koko-and-friend-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "#angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "koko-and-friend:serve"
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "koko-and-friend"
}
When I check the heroku console using bash 'dir', the dist/koko-and-friend folder after the angular app was built is there. This is weird because I'm using this same option for angular 4 exluding the #angular-devkit/build-angular in preinstall. I also checked heroku logs and there's no error.
Try to replace following line in your server.js
app.use(express.static(path.join(__dirname, '/dist')));
with
app.use( express.static(path.join(__dirname, '/dist/koko-and-friend')));
Your NPM scripts don't have any logic about moving your content to a specific folder.
This means that your page should be on dist/index.html, not dist/koko-and-friend/index.html.
Please, also post the content of your angular-cli.json (v5) or angular.json (v6) file.
Written one mocha test case with chai in Typescript and followed the article http://brianflove.com/2016/11/11/typescript-2-express-mongoose-mocha-chai/ to install all dependencies.
While I am running the test cases with "npm test", I am getting below error
C:\J\MEAN\MSDN-App\node_modules\#angular\core\bundles\core.umd.js:335
throw 'reflect-metadata shim is required when using class decorators';
^
reflect-metadata shim is required when using class decorators
npm ERR! Test failed. See above for more details.
The package.json is:
{
"name": "test-app",
"version": "1.0.0",
"description": "test description",
"main": "server.js",
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"test": "mocha -r ts-node/register test/**/*.ts",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
},
"author": "",
"license": "ISC",
"dependencies": {
"#angular/common": "^2.0.1",
"#angular/compiler": "^2.0.1",
"#angular/core": "^2.0.1",
"#angular/forms": "^2.0.1",
"#angular/http": "^2.0.1",
"#angular/platform-browser": "^2.0.1",
"#angular/platform-browser-dynamic": "^2.0.1",
"#angular/router": "^3.4.10",
"#angular/upgrade": "^2.0.1",
"#covalent/core": "^1.0.0-beta.3-2",
"#ngrx/store": "^2.0.1",
"#types/node": "7.0.7",
"#types/underscore": "^1.8.0",
"angular-in-memory-web-api": "^0.1.1",
"body-parser": "^1.17.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"ejs": "^2.5.6",
"express": "^4.15.2",
"mongojs": "^2.4.0",
"node-sspi": "^0.1.14",
"nodemailer": "^4.0.1",
"nodemailer-smtp-transport": "^2.7.4",
"properties-reader": "0.0.15",
"reflect-metadata": "^0.1.10",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"ts-node": "^3.0.4",
"underscore": "^1.8.3",
"zone.js": "^0.6.25"
},
"devDependencies": {
"#types/chai": "^3.5.2",
"#types/core-js": "0.9.35",
"#types/mocha": "^2.2.41",
"chai": "^3.5.0",
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"mocha": "^3.4.1",
"reflect-metadata": "^0.1.10",
"ts-node": "^3.0.4",
"typescript": "^2.0.3",
"typings": "^1.4.0"
}
}
And tsconfig.json is:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"node_modules/#types",
"bower_components",
"typings"
]
}
Please help to resolve the error.
Very simple answer but hard to find out. Should not include the #angular/http in test.ts files and to test services use unit testing, to test angular components we must test with Angular testing utilities.
I am trying to read file in Typescripts. I am using #types/node instead of typings.
There is no compile error. But the fs in the debugger is shown as undefined.
What have I missed?
test.ts
import * as fs from 'fs';
fs.readFile('../some.xml', 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
console.log(data);
});
tsconfig.app.json
{
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"outDir": "./dist",
"target": "es5",
"module": "es2015",
"baseUrl": "",
"typeRoots": [
"node_modules/#types"
],
"types": [
"node"
]
},
"filesGlob": [
"./node_modules/#types//.d.ts"
],
"exclude": [
"test-helpers",
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"genDir": "./locale"
}
}
package.json
{
"name": "myApp",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/common": "^2.4.0",
"#angular/compiler": "^2.4.0",
"#angular/core": "^2.4.0",
"#angular/forms": "^2.4.0",
"#angular/http": "^2.4.0",
"#angular/platform-browser": "^2.4.0",
"#angular/platform-browser-dynamic": "^2.4.0",
"#angular/router": "^3.4.0",
"#ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.20",
"angular2-logger": "^0.5.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"rxjs": "^5.1.0",
"socket.io-client": "^1.7.2",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.6"
},
"devDependencies": {
"#angular/cli": "1.0.0-rc.0",
"#angular/compiler-cli": "^2.4.0",
"#types/jasmine": "2.5.38",
"#types/node": "~6.0.60",
"#types/socket.io-client": "^1.4.29",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-coverage-istanbul-reporter": "^0.2.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "~2.0.0"
}
}
I was able to fix this by installing the typings files for node:
typings install dt~node --global --save