【发布时间】:2017-02-20 09:49:14
【问题描述】:
Typescript 2.0 的 Express 类型定义在运行 ES6 的 npm install @types/express 和 tsc -t ES6 后执行时会导致意外错误。代码在没有 ES6 标志的情况下编译得很好。谁能解释一下?我也有其他类型定义的问题,例如ssh2。
重现步骤如下:
> mkdir humbug
> cd humbug
> touch blank.ts
> tsc blank.ts
> tsc -t ES6 .\blank.ts
到目前为止一切都很好。
> npm init .
...
> npm install @types/express
事情开始变糟了
> tsc blank.ts
> tsc -t ES6 .\blank.ts
node_modules/@types/express/index.d.ts(16,30): error TS2307: Cannot find module 'serve-static'.
node_modules/@types/serve-static/index.d.ts(16,20): error TS2307: Cannot find module 'mime'.
好的,我最好确保已安装 serve-static 和 mime 类型。
> npm install @types/serve-static @types/mime
humbug@1.0.0 C:\Users\me\Desktop\humbug
`-- (empty)
npm WARN humbug@1.0.0 No description
npm WARN humbug@1.0.0 No repository field.
npm ERR! code 1
奇怪的是我得到了一个错误!代码但类型已下载,让我们重新编译一次
> tsc blank.ts
> tsc -t ES6 .\blank.ts
node_modules/@types/express/index.d.ts(16,30): error TS2307: Cannot find module 'serve-static'.
node_modules/@types/serve-static/index.d.ts(16,20): error TS2307: Cannot find module 'mime'.
和上次一样的错误。
我的环境:
- Windows 10
- 节点 v6.6.0
- TSC 2.0.3
存在相同问题的其他定义:
node_modules/@types/cors/index.d.ts(9,26): error TS2307: Cannot find module 'express'.
node_modules/@types/multer/index.d.ts(6,26): error TS2307: Cannot find module 'express'.
node_modules/@types/ssh2/index.d.ts(26,8): error TS2307: Cannot find module 'ssh2-streams'.
【问题讨论】:
标签: express typescript-typings tsc typescript2.0