【发布时间】:2022-01-13 14:22:08
【问题描述】:
在我的NodeJS/TypeScript 项目中,我使用的是fluent-ffmpeg,它运行良好。
为了使用它,我需要导入ffmpeg-installer/ffmpeg 和ffprobe-installer/ffprobe 的path 属性。
ffmpeg 导入看起来像:
import * as ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
@ffmpeg-installer/ffmpeg 模块的types 文件夹下存在声明文件index.d.ts 使之成为可能。
关于ffprobe 这是不可能的,因为缺少像上面提到的那样的声明文件。尝试时:import * as ffprobeInstaller from "@ffprobe-installer/ffprobe"; 出现错误:
找不到模块“@ffprobe-installer/ffprobe”的声明文件。 '<...>/node_modules/@ffprobe-installer/ffprobe/index.js' 隐含地具有 'any' 类型。 尝试
npm i --save-dev @types/ffprobe-installer__ffprobe(如果存在)或添加包含declare module '@ffprobe-installer/ffprobe';ts(7016) 的新声明(.d.ts)文件
npm i --save-dev @types/ffprobe-installer__ffprobe 都没有给出任何东西。
所以我改用const ffprobeInstaller = require("@ffprobe-installer/ffprobe");,它可以工作。
然而,ESLint 来了并抱怨:
Require 语句不是 import 语句的一部分。 eslint (@typescript-eslint/no-var-requires)
所以我尝试将其替换为:import ffprobeInstaller = require("@ffprobe-installer/ffprobe");,正如ESLint 文档中所建议的那样,但后来我又得到了Could not find a declaration file...ts(7016)。
我可以采取一些方向来解决这个问题:
- 创建我自己的声明文件
- 禁用
no-var-requires规则或在本地忽略它
我的问题是:如何在不创建声明文件或禁用规则的情况下通过 ESLint 的 no-var-requires 规则。
【问题讨论】:
-
你试过写
// eslint-disable-next-line @typescript-eslint/no-var-requires,就在require的上方吗?
标签: typescript eslint node-modules