我开始使用typescript并安装了node和express,body-parser的输入文件。当我尝试运行编译,但在编译时,我看到它无法导入快速和正文解析器的错误。但是我也分别为所有这些节点模块安装了节点模块,所以在tsc编译代码后它会正常运行。但编译错误仍然存在。
错误
app.ts(2,26):错误TS2307:找不到模块'express'。
app.ts(9,12):错误TS2304:找不到名称'process'。
import express = require('express');
let app = express();
app.get('/',(req,res)=>{
res.send("Hello");
})
// Listen for HTTP traffic
app.listen(process.env.PORT || 3000);
答案 0 :(得分:0)
代码可以正常运行
TypeScript就像一个非常强大的linter。即使存在类型错误,它也总是会尝试为您提供JavaScript。因此,即使出现错误,您的代码也可能正常运
https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html
但编译错误仍然存在。
如果你没有分享更多的代码/步骤,我帮不了你?
此项目使用快递:https://github.com/alm-tools/alm
快速入门的文档:https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
答案 1 :(得分:0)
所以,我发现的第一个错误是我的app.ts我没有引用main.d.ts文件。
/// <reference path="typings/main.d.ts" />
然后仍然是错误来了。
所以安装以下的打字。
typings install serve-static --ambient --save
typings install express-serve-static-core --ambient --save
typings install mime --ambient --save
瞧,没有编译错误