I am starting with typescript and installed the typing files for node and express,body-parser. When i try to run compile , but on compiling I see the errors that it cannot import express and body parser. But I also installed the node modules separately for all of them so after tsc compiles the code it would run fine . But the compilation errors are still there.
The Errors
app.ts(2,26): error TS2307: Cannot find module 'express'.
app.ts(9,12): error TS2304: Cannot find name '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);
code it would run fine
TypeScript is like a really powerful linter. It will always try to give you JavaScript even in the presence of type errors. So your code might run fine even with errors.
https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html
But the compilation errors are still there.
I cannot help you much without you sharing more code / steps you took?
This project uses express : https://github.com/alm-tools/alm
Also docs on a quickstart : https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html
So , first mistake with my code i found was that i my app.ts i was not referencing the main.d.ts file. /// <reference path="typings/main.d.ts" />
then still the errors were coming . so installed typings for the following.
typings install serve-static --ambient --save
typings install express-serve-static-core --ambient --save
typings install mime --ambient --save
and voila, no compile errors
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.