Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. "ZoneAwareError.__zone_symbol__error (SystemJS) Unexpected value 'Http' imported by the module 'AppModule'
  2. Error: Unexpected value 'Http' imported by the module 'AppModule'
  3. at SyntaxError.ZoneAwareError (http://localhost:3000/node_modules/zone.js/dist/zone.js:811:33)
  4. at SyntaxError.BaseError [as constructor] (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1592:20)
  5. at new SyntaxError (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1795:20)
  6. at eval (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:18301:48)
  7. at Array.forEach (native)
  8. at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:18286:53)
  9. at JitCompiler._loadModules (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27360:68)
  10. at JitCompiler._compileModuleAndComponents (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27320:56)
  11. at JitCompiler.compileModuleAsync (http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27286:25)
  12. at PlatformRef_._bootstrapModuleWithZone (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8081:29)
  13. at PlatformRef_.bootstrapModule (http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:8056:25)
  14. at Object.eval (http://localhost:3000/app/main.js:4:53)
  15. at eval (http://localhost:3000/app/main.js:6:4)
  16. at eval (http://localhost:3000/app/main.js:7:3)
  17. at eval (<anonymous>)
  18. Evaluating http://localhost:3000/app/main.js
  19. Error loading http://localhost:3000/app/main.js"
  20.  
  21. function initConfig(config: AppConfig){
  22. return () => config.load()
  23. }
  24.  
  25. @NgModule({
  26. imports: [ BrowserModule, FormsModule, ReactiveFormsModule],
  27. declarations: [ AppComponent ],
  28. bootstrap: [ AppComponent ],
  29. providers: [HttpModule, AppConfig, { provide: APP_INITIALIZER, useFactory: initConfig, deps: [AppConfig], multi: true }]
  30. })
  31.  
  32.  
  33. export class AppModule { }
  34.  
  35. @Injectable()
  36. export class AppConfig {
  37.  
  38. private config: Object = null;
  39. private env: Object = null;
  40.  
  41. constructor(private http: Http) {
  42.  
  43. }
  44.  
  45. /**
  46. * Use to get the data found in the second file (config file)
  47. */
  48. public getConfig(key: any) {
  49. return this.config[key];
  50. }
  51.  
  52. /**
  53. * Use to get the data found in the first file (env file)
  54. */
  55. public getEnv(key: any) {
  56. return this.env[key];
  57. }
  58.  
  59. /**
  60. * a) Loads "env.json" to get the current working environment (e.g.: 'production', 'development')
  61. * b) Loads "config.[env].json" to get all env's variables (e.g.: 'config.development.json')
  62. */
  63. public load() {
  64. return new Promise((resolve, reject) => {
  65. this.http.get('./app/conf/env.json').map( res => res.json() ).catch((error: any):any => {
  66. console.log('Configuration file "env.json" could not be read');
  67. resolve(true);
  68. return Observable.throw(error.json().error || 'Server error');
  69. }).subscribe( (envResponse) => {
  70. this.env = envResponse;
  71. let request:any = null;
  72.  
  73.  
  74. switch (envResponse["env"]) {
  75. case 'production': {
  76. request = this.http.get('app/conf/config.' + envResponse["env"] + '.json');
  77. } break;
  78.  
  79. case 'development': {
  80. request = this.http.get('app/conf/config.' + envResponse["env"] + '.json');
  81. } break;
  82.  
  83. case 'default': {
  84. console.error('Environment file is not set or invalid');
  85. resolve(true);
  86. } break;
  87. }
  88.  
  89. if (request) {
  90. request
  91. .map( res => res.json() )
  92. .catch((error: any) => {
  93. console.error('Error reading ' + envResponse["env"] + ' configuration file');
  94. resolve(error);
  95. return Observable.throw(error.json().error || 'Server error');
  96. })
  97. .subscribe((responseData) => {
  98. debugger;
  99. this.config = responseData;
  100. resolve(true);
  101. });
  102. } else {
  103. console.error('Env config file "env.json" is not valid');
  104. resolve(true);
  105. }
  106. });
  107.  
  108. });
  109. }
  110. }
  111.  
  112. @Injectable()
  113. export class AnyClass {
  114. constructor(private http: Http, private config: AppConfig) {
  115. this.config = config;
  116. }
  117. ...
  118. let host:string = this.config.getConfig('host');
  119.  
  120. {
  121. "name": "angular-quickstart",
  122. "version": "1.0.0",
  123. "description": "QuickStart package.json from the documentation, supplemented with testing support",
  124. "scripts": {
  125. "build": "tsc -p app/",
  126. "build:watch": "tsc -p app/ -w",
  127. "build:e2e": "tsc -p e2e/",
  128. "serve": "lite-server -c=bs-config.json",
  129. "serve:e2e": "lite-server -c=bs-config.e2e.json",
  130. "prestart": "npm run build",
  131. "start": "concurrently "npm run build:watch" "npm run serve"",
  132. "pree2e": "npm run build:e2e",
  133. "e2e": "concurrently "npm run serve:e2e" "npm run protractor" --kill-others --success first",
  134. "preprotractor": "webdriver-manager update",
  135. "protractor": "protractor protractor.config.js",
  136. "pretest": "npm run build",
  137. "test": "concurrently "npm run build:watch" "karma start karma.conf.js"",
  138. "pretest:once": "npm run build",
  139. "test:once": "karma start karma.conf.js --single-run",
  140. "lint": "tslint ./app/**/*.ts -t verbose"
  141. },
  142. "keywords": [],
  143. "author": "",
  144. "license": "MIT",
  145. "dependencies": {
  146. "@angular/common": "~2.4.0",
  147. "@angular/compiler": "~2.4.0",
  148. "@angular/core": "~2.4.0",
  149. "@angular/forms": "~2.4.0",
  150. "@angular/http": "~2.4.0",
  151. "@angular/platform-browser": "~2.4.0",
  152. "@angular/platform-browser-dynamic": "~2.4.0",
  153. "@angular/router": "~3.4.0",
  154. "bootstrap": "^3.3.7",
  155. "angular-in-memory-web-api": "~0.2.4",
  156. "systemjs": "0.19.40",
  157. "core-js": "^2.4.1",
  158. "rxjs": "5.0.1",
  159. "reflect-metadata": "^0.1.9",
  160. "zone.js": "^0.7.4"
  161. },
  162. "devDependencies": {
  163. "concurrently": "^3.2.0",
  164. "lite-server": "^2.2.2",
  165. "typescript": "~2.0.10",
  166.  
  167. "canonical-path": "0.0.2",
  168. "tslint": "^3.15.1",
  169. "lodash": "^4.16.4",
  170. "jasmine-core": "~2.4.1",
  171. "karma": "^1.3.0",
  172. "karma-chrome-launcher": "^2.0.0",
  173. "karma-cli": "^1.0.1",
  174. "karma-jasmine": "^1.0.2",
  175. "karma-jasmine-html-reporter": "^0.2.2",
  176. "protractor": "~4.0.14",
  177. "rimraf": "^2.5.4",
  178.  
  179. "@types/node": "^6.0.46",
  180. "@types/jasmine": "2.5.36"
  181. },
  182. "repository": {}
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement