首页 > 解决方案 > 找不到模块“is_js”的声明文件

问题描述

我有两个打字稿项目。我在两者的 package.json 中都有这些依赖项:

"dependencies": {
   "is_js": "^0.9.0"
},
"devDependencies": {
   "@types/is": "0.0.21",
},

两个 tsconfig.json-s 都包含

  "strict": true

我在这两个代码中都有这行 TypeScript 代码:

import * as IsJS from 'is_js';

在其中一个项目中,我收到编译器错误:

找不到模块“is_js”的声明文件。'/Volumes/Me/Project/node_modules/is_js/is.js' 隐含了一个 'any' 类型。尝试npm i --save-dev @types/is_js它是否存在或添加一个新的声明 (.d.ts) 文件,其中包含declare module 'is_js';

另一个项目编译得很好,我还可以在 VSCode 悬停工具提示中看到 IsJS 对象的输入信息。请帮我弄清楚这个项目可能出了什么问题。

标签: typescript

解决方案


I still don't know the cause of this, but at least I've found a workaround. Write this line at the top of the file that imports IsJS:

/// <reference types="is_js" />

This makes the type declarations available in that file even though they weren't found automatically.


推荐阅读