首页 文章

Typescript项目编译错误

提问于
浏览
0

我开始使用typescript并安装了node和express,body-parser的输入文件 . 当我尝试运行编译时,但在编译时,我看到它无法导入快速和正文解析器的错误 . 但是我还为所有这些模块分别安装了节点模块,因此在tsc编译代码之后它会正常运行 . 但编译错误仍然存在 .

错误

app.ts(2,26):错误TS2307:找不到模块'express' .

app.ts(9,12):错误TS2304:找不到名称'进程' .

import express = require('express');

let app = express();
app.get('/',(req,res)=>{
    res.send("Hello");
})
// Listen for HTTP traffic
app.listen(process.env.PORT || 3000);

2 回答

  • 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

  • 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
    

    瞧,没有编译错误

相关问题