javascript TypeScript模块解析错误:“找不到模块的声明文件”,我错过了什么?

aiazj4mn  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(322)

我无法将JS库添加到我的TS项目。我安装了一个JS库。
当我尝试运行服务器时,我得到以下错误:

`Could not find a declaration file for module 'lyrics-finder'. '' implicitly has an 'any' type.
Try `npm i --save-dev @types/lyrics-finder` if it exists or add a new declaration (.d.ts) file containing `declare module 'lyrics-finder';``

这个库没有@types/lyrics-finder,所以我需要创建一个新的声明,但我总是失败。
我创建了lyrics-finder.d.ts文件:

`declare module 'lyrics-finder' {
  export default function lyricsFinder(artist: string | undefined, title: string | undefined): Promise<string | null>;
}`

我把这个放在类型文件夹里。然后我更新了一个tsconfig.json(添加了“typeRoots”,“baseUrl”)

*{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "module": "ESNext",
    "typeRoots": ["src/types"],
    "declaration": true,
    "baseUrl": "src",

    /* Bundler mode */
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },*

但所有这些都没有帮助,我仍然得到同样的错误,模块没有建立。你知道为什么吗

kqlmhetl

kqlmhetl1#

查看NPM page for that project,指向their github page的链接重定向到一个类似的包,但名称不同lyrics-searcher
lyrics-searcher似乎是built in TypeScript,并且在其包中包含typedef
所以,我想你可能可以只使用这个包代替,它似乎是由同一个开发人员。我想他们只是重新命名了。

相关问题