2017-05-18 56 views
0

我一直緊跟着步驟這個簡單的教程一步,但我得到這個404錯誤 enter link description here打字稿與systemjs配置錯誤

我敢肯定,我已經安裝了打字稿本地

npm install typescript --save 

(打字稿在node_modules文件夾存在)

這是精簡版服務器的輸出

17.05.18 09:14:25 200 GET /index.html 
17.05.18 09:14:25 200 GET /node_modules/systemjs/dist/system.js 
17.05.18 09:14:25 200 GET /node_modules/systemjs/dist/system.js.map 
17.05.18 09:14:25 200 GET /node_modules/typescript/lib/typescript.js 
17.05.18 09:14:25 200 GET /src/main.ts 
17.05.18 09:14:25 404 GET /typescript 

,並在瀏覽器控制檯

[object Error]{description: "Fetch error...", message: "Fetch error...", name: "Error", originalErr: Error {...}, stack: "Error: Fetc..."} 
Instantiating http://localhost:3000/typescript 
Loading typescript 
Unable to load transpiler to transpile http://localhost:3000/src/main.ts 
Instantiating http://localhost:3000/src/main.ts 

我怎樣才能進一步調查?


項目結構:

. 
├── index.html 
├── package.json 
└── src 
    ├── main.ts 
    └── person.ts 

的index.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>SystemJS</title> 
    <script src="node_modules/systemjs/dist/system.js"></script> 
    <script src="node_modules/typescript/lib/typescript.js"></script> 
    <script> 
    System.config({ 
     transpiler: 'typescript', 
     packages : { 
      src: { 
       defaultExtension: 'ts' 
      } 
     } 
    }); 
    System 
     .import('src/main') 
     .then(null, console.error.bind(console)); 
    </script> 
</head> 
<body> 
</body> 
</html> 

main.ts

import { Person } from './person'; 

let person = new Person(); 
console.log(person.name); 

person.ts

export class Person { 
    public name: string = 'xxxxxx'; 
} 
+0

你能在控制檯中得到的錯誤中發佈完整的消息嗎? – toskv

+0

請提供源代碼,很難說沒有看到您的代碼的東西。 –

+0

提供的源代碼 – alex

回答

1

我跟着你提供的鏈接,爲你創建了一個有效的plunkr演示。

Plunker Demo

這是我的index.html長相如何腳本。希望這可以幫助。

<script src="https://unpkg.com/[email protected]/dist/system.js"></script> 
<script> 
    System.config({ 
    transpiler: 'typescript', 
    packages: { 
     src: { 
     defaultExtension: 'ts' 
     } 
    }, 
    paths: { 
     'npm:': 'https://unpkg.com/' 
    }, 
    map: { 
     'typescript': 'npm:[email protected]/lib/typescript.js' 
    } 
    }); 
    System 
    .import('src/main') 
    .then(null, console.error.bind(console)); 
</script> 
+0

首先感謝您的闖入者!添加「路徑」和「地圖」屬性到我的代碼工作的SystemJS配置,並且我注意到,lite服務器的輸出沒有在「/ typescript」路徑上顯示404。這是否意味着它從遠程加載打字稿? (sort for cdn?)或正在從node_modules文件夾加載。如果它是真的「第一個」,爲什麼本教程中的代碼沒有「路徑」和「地圖」屬性的作用 – alex

+0

在教程中,typescript是從node_module文件夾中引用的,您可以在上一個'index.html'代碼示例中看到它。在我的plunkr例子中,它通過CDN(unpkg.com)加載,你可以在路徑部分看到它。 –