找不到模块“ vimeo”的声明文件

时间:2019-04-06 17:20:48

标签: javascript node.js typescript

我正在使用节点v11.3.0在Express应用程序(^ 4.14.1)中使用打字稿v ^ 3.4.2。

当我为打字稿运行构建时,出现以下错误:

Could not find a declaration file for module 'vimeo'. '/Users/me/Code/MyServer/node_modules/vimeo/index.js' implicitly has an 'any' type.
  Try `npm install @types/vimeo` if it exists or add a new declaration (.d.ts) file containing `declare module 'vimeo';`

1 import { Vimeo } from "vimeo";

我正在将Vimeo api客户端用于2.1.1版的nodejs vimeo.js

我尝试运行yarn add --dev @types/vimeo,但是很遗憾,该库是 other vimeo库vimeo/player.js的库。安装它没有用。

我尝试遵循this article创建自己的自定义类型声明。

这是我的tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*"]
    },
    "typeRoots": ["./types", "./node_modules/@types"]
  },
  "include": ["src/**/*", "controllers/**/*", "routes/**/*", "models/**/*"],
  "exclude": ["node_modules", "types"]
}

我创建了/Users/me/Code/MyServer/types/vimeo/vimeo.d.ts,其中包含:

declare module vimeo {}

当我添加该错误时,将变为:

yarn run v1.15.2
$ yarn build
$ tslint -c tslint.json -p tsconfig.json --fix
$ tsc
error TS2688: Cannot find type definition file for 'vimeo'.

文章还建议在其中添加具有相同定义的根global.d.ts,但这无效。

我很困惑。任何帮助将不胜感激。

(这是我的package.json脚本块:)

 "main": "dist/app.js",
  "scripts": {
    "prebuild": "tslint -c tslint.json -p tsconfig.json --fix",
    "build": "tsc",
    "prestart": "yarn build",
    "start": "babel-node dist/app.js --presets es2015",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

这是我的tslint.json

{
  "defaultSeverity": "error",
  "extends": ["tslint:recommended"],
  "jsRules": {},
  "rules": {
    "trailing-comma": [false],
    "curly": [true, "ignore-same-line"],
    "ban-types": false
  },
  "rulesDirectory": []
}

0 个答案:

没有答案