2017-05-18 60 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)加载,你可以在路径部分看到它。 –