typescript - 找不到模块“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 对象的输入信息。请帮我弄清楚这个项目可能出了什么问题。
解决方案
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.
推荐阅读
- node.js - 我如何解析来自 nrf24 缓冲区的 JSON?
- react-router - 反应路由器订购
- javascript - 如何将我的 postgis 点加载到传单中
- r - 带有 4 个图表堆栈的 flexdashboard
- angular - 角度别名路径在 Intellij 中没有得到解决
- r - R 中的简单模拟:随机模拟均值与截断正态期望不匹配
- c++ - 如何在 DEV C++ IDE 中使用文本文件进行标准输入?
- c - C - 无法在我的程序中启动堆栈
- c++ - 使用 MODULEENTRY32 和 MODULEINFO,在单独的进程中扫描特定 INT 值的步骤是什么?
- c# - Startup.cs 中的 OpenIdConnectAuthenticationOptions 问题(AuthenticationFailed 属性)