我正在尝试在我的应用中使用 expressjs。
使用 typings install express --ambient --save
安装后,我运行 tsc
,但出现两个错误:
typings/main/ambient/express/index.d.ts(17,34): error TS2307: Cannot find module 'serve-static'. typings/main/ambient/express/index.d.ts(18,27): error TS2307: Cannot find module 'express-serve-static-core'.
所以,我尝试同时安装:
typings install serve-static --ambient --save
typings install express-serve-static --ambient --save
然后我再次运行 tsc,但又出现一个错误:
typings/main/ambient/serve-static/index.d.ts(79,24): error TS2307: Cannot find module 'mime'.
如何解决这些问题?如何自动安装 express 的所有依赖项?
最佳答案
使用 Typescript 2.0( https://blogs.msdn.microsoft.com/typescript/2016/09/22/announcing-typescript-2-0/ ),现在不同了:
如果您使用以下命令安装 typescript:
npm install -g typescript@2.0
你必须使用命令安装 express typings
npm install --save @types/express
而不是像早期版本那样使用环境/全局安装类型。 typings 安装在 node_modules/@types/express
目录
在执行 types
的 npm install
之后,您的 package.json 将包含以下片段:
"dependencies": {
"@types/express": "^4.0.33"
}
关于typescript - 如何在打字中安装 express ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36037977/