2017-04-14 88 views
0

我是Angular2的新手。我正在關注Tutorial Angular2 by Example。這是第一個簡單的教程叫做猜數Angular2 intelliJ配置錯誤..找不到模塊'@ angular/core'

我使用的代碼完全按照github提供的示例 https://github.com/chandermani/angular2byexample/tree/master/guessthenumber中所述。

它在瀏覽器中加載正常。這是IntelliJ安裝,我有問題。

IntelliJ返回以下錯誤..如截圖所示。 找不到模塊 '@角/核心'

enter image description here

我的屬性文件如下

systemjs.config.js

System.config({ 
map : { 
    'app': 'app', 
    'rxjs': 'https://unpkg.com/[email protected]', 
    '@angular/common': 'https://unpkg.com/@angular/[email protected]', 
    '@angular/compiler': 'https://unpkg.com/@angular/[email protected]', 
    '@angular/core': 'https://unpkg.com/@angular/[email protected]', 
    '@angular/platform-browser': 'https://unpkg.com/@angular/[email protected]', 
    '@angular/platform-browser-dynamic': 'https://unpkg.com/@angular/[email protected]' 
}, 
packages:{ 
    'app': { main: 'main.ts', defaultExtension: 'ts' }, 
    '@angular/common': { main: 'bundles/common.umd.js', defaultExtension: 'js' }, 
    '@angular/compiler': { main: 'bundles/compiler.umd.js', defaultExtension: 'js' }, 
    '@angular/core': { main: 'bundles/core.umd.js', defaultExtension: 'js' }, 
    '@angular/platform-browser': { main: 'bundles/platform-browser.umd.js', defaultExtension: 'js' }, 
    '@angular/platform-browser-dynamic': { main: 'bundles/platform-browser-dynamic.umd.js', defaultExtension: 'js' }, 
}, 
// DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER 
transpiler: 'typescript', 
typescriptOptions: { 
    emitDecoratorMetadata: true 
} 
}); 

我的上一個潛在的解決方案的想法?

  1. 當前加載模塊從https://unpkg.com/@angular/[email protected]不過的IntelliJ情願將其從計算機上的文件被加載?我應該在本地託管文件嗎?

  2. Intellij不知道systemjs.config.js文件?我需要創建一個tsconfig.json文件嗎? Intellij能理解嗎?

回答

1

錯誤來自TS編譯器。是的,就像Idea本身一樣,它在系統配置中不能找到CDN引用的@angular模塊:它需要項目中本地可用的模塊(通過npm安裝 - 例如參見https://angular.io/docs/ts/latest/guide/setup.html)。像你這樣的配置只有在使用基於瀏覽器的編譯時才能工作

+0

查看使用本地模塊時的系統配置可能如何:https://github.com/johnpapa/angular-tour-of-heroes/blob/master/system-config.ts – lena

+0

我認爲此評論指向正確的方向然而,這個例子有很多我不需要的東西。 –

+0

我解釋了Idea中的錯誤;我提供的鏈接僅僅是一個例子,而不是一個隨時可用的解決方案 – lena

0

是的,我想你需要創建tsconfig.json,

,並開啓中的IntelliJ設置

enter image description here

打字稿編譯器也該answer也可以幫助你

+0

tsconfig文件中會出現什麼內容? –

相關問題