【问题标题】:Could not find a declaration file for module 'vimeo'找不到模块“vimeo”的声明文件
【发布时间】:2022-03-18 07:31:39
【问题描述】:

我在快速应用程序 (^4.14.1) 中使用 typescript v^3.4.2,使用节点 v11.3.0。

当我为 typescript 运行构建时,我收到以下错误:

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";

我正在使用适用于 nodejs vimeo.js 的 Vimeo api 客户端,版本 2.1.1。

我尝试运行 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": []
}

【问题讨论】:

  • 我强烈建议您尽快使用最新的 Node LTS 版本。 Node 11 从来都不是 LTS 版本,甚至 Node 12 也将在几周后 完全 退出支持计划,届时 Node 18 将成为当前版本,而 Node 14 将成为最旧的仍在支持的版本节点版本。

标签: javascript node.js typescript


【解决方案1】:

如果我没记错的话,设置"noImplicityAny": false, 可以解决声明文件的问题...或者您可以为该模块寻找一些.d.ts(或者甚至自己制作并在GitHub 中提出拉取请求)

【讨论】:

    猜你喜欢
    • 2017-08-13
    • 1970-01-01
    • 2021-01-02
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    相关资源
    最近更新 更多