2016-12-31 81 views
2

UPDATE@types找不到404 angular2

我在這裏https://www.dropbox.com/s/g3k4phhqffleeh0/jsapi4-angular2.zip?dl=0添加的代碼,有人請幫助:(

========

我有一個角度2的項目,我分叉並開始工作

一切都很好,花花公子,直到我真的需要安裝一些類型和使用它們。在類型上,可以找到它們。建設也不是問題。但是SystemJS似乎無法找到類型。我一直在爭奪這個約10小時,似乎無法找到一個解決辦法:(請幫助。

Screenshot of chrome console

systemjs.config.js

/** 
* System configuration for Angular 2 samples 
* Adjust as necessary for your application needs. 
*/ 
(function (global) { 
System.config({ 
transpiler: 'typescript', 

paths: { 
    // paths serve as alias 
    'npm:': 'node_modules/' 
}, 
// map tells the System loader where to look for things 
map: { 
    'app': 'app', // 'dist', 

    // angular bundles 
    '@angular/core': 'npm:@angular/[email protected]/bundles/core.umd.js', 
    '@angular/common': 'npm:@angular/[email protected]/bundles/common.umd.js', 
    '@angular/compiler': 'npm:@angular/[email protected]/bundles/compiler.umd.js', 
    '@angular/platform-browser': 'npm:@angular/[email protected]/bundles/platform-browser.umd.js', 
    '@angular/platform-browser-dynamic': 'npm:@angular/[email protected]/bundles/platform-browser-dynamic.umd.js', 
    '@angular/http': 'npm:@angular/[email protected]/bundles/http.umd.js', 
    '@angular/router': 'npm:@angular/[email protected]/bundles/router.umd.js', 

    // angular testing umd bundles 
    '@angular/core/testing': 'npm:@angular/[email protected]/bundles/core-testing.umd.js', 
    '@angular/common/testing': 'npm:@angular/[email protected]/bundles/common-testing.umd.js', 
    '@angular/compiler/testing': 'npm:@angular/[email protected]/bundles/compiler-testing.umd.js', 
    '@angular/platform-browser/testing': 'npm:@angular/[email protected]/bundles/platform-browser-testing.umd.js', 
    '@angular/platform-browser-dynamic/testing': 'npm:@angular/[email protected]/bundles/platform-browser-dynamic-testing.umd.js', 
    '@angular/http/testing': 'npm:@angular/[email protected]/bundles/http-testing.umd.js', 
    '@angular/router/testing': 'npm:@angular/[email protected]/bundles/router-testing.umd.js', 

    // other libraries 
    'rxjs': 'npm:[email protected]', 
    'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', 

    'esri': 'http://js.arcgis.com/4.0/esri' 
}, 

// packages tells the System loader how to load when no filename and/or no extension 
packages: { 
    app: { 
    main: './main.js', 
    defaultExtension: 'js' 
    }, 
    rxjs: { 
    defaultExtension: 'js' 
    }, 
    'angular2-in-memory-web-api': { 
    main: './index.js', 
    defaultExtension: 'js' 
    }, 
    '@types/highcharts': {defaultExtension: 'ts'} 
} 
}); 
})(this); 

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "system", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "lib": [ "es2015", "dom" ], 
    "noImplicitAny": false, 
    "suppressImplicitAnyIndexErrors": true, 
    "typeRoots": ["jsapi4-angular2/node_modules/", "jsapi4-angular2/typings/"] 
    }, 
    "exclude": [ 
    "node_modules/zone.js", 
    "node_modules/concurrently", 
    "node_modules/lite-server", 
    "node_modules/typescript", 
    "node_modules/typings", 
    "node_modules/reflect-metadata", 
    "node_modules/rxjs", 
    "node_modules/tslint", 
    "bower_components", 
    "typings/main", 
    "typings/main.d.ts" 
    ] 
} 

esriSystemLoadBrowser.js

// load esri modules needed by this application 
// into a System.js module called esri 
console.log("Loading esri modules: ", esriLoadConfig.modules); 
start = performance.now(); 
esriSystem.register(esriLoadConfig.modules, function() { 
    // then bootstrap application 
    end = performance.now(); 
    time = end - start; 
    console.log('Loaded esri modules', time/1000.0); 
    System.config({ 
     transpiler: 'typescript' 
    }); 
    System.import('app/main').then(function() { 
    console.log('app/main imported'); 
    }, function (error) { 
    console.log("System import error:", error); 
    }); 
}); 
+0

你應該嘗試掛接對應於類型的JS文件,而不是類型本身。類型只是編譯時。 JS文件用於運行時 –

+0

你會碰巧知道如何做到這一點?很抱歉的愚蠢的問題:/ –

+0

我從不使用highcharts,所以我不能過頭頂說。這是我需要測試的東西,但我現在沒有我的工具。 –

回答

0

在tsconfig的compilerOptions嘗試類型明確列出的類型定義文件的名稱,它無法找到替換typeRoots:

types:[...]

此外,使用"module": "commonjs"

+0

我做了你說的但仍然沒有成功。也爲@ types/highcharts正確添加了一個路徑和包的值。這樣做讓我回到了原來的位置。當我刪除他們,只是離開類型和模塊:commonjs然後我看到這個錯誤 從http:// localhost:從http:// localhost:加載http:// localhost:3003/@types/highcharts.js爲「@ types/highcharts」 3003 /應用程序/服務/ map.service.ts –