【发布时间】:2017-05-19 03:25:40
【问题描述】:
我一步一步地按照这个简单的教程,但我得到了这个 404 错误 enter link description here
我确定我已经在本地安装了 typescript
npm install typescript --save
(存在 node_modules 文件夹中的打字稿)
这是 lite-server 的输出
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';
}
【问题讨论】:
-
您能否在控制台收到的错误中发布完整消息?
-
请提供源代码,不看代码很难说。
-
提供源代码
标签: typescript systemjs