我正试图在项目中使用log4javascript,我发现该包在node_modules/log4javascript/中确实存在log4javascript.d.ts,package.json确实在"typeings"属性中引用了它,但在编译我的项目时,它会抱怨:
S2307:找不到模块"log4javascript">
我正在使用导入模块
import {getLogger } from 'log4javascript';
据我所知,一个人不需要单独安装打字机:
npm install@types/log4javascript
因为已经存在键入。但我不确定如何使用模块类型和方法,如果我有:
"noImplicitAny": true,
在我的tsconfig.json 中设置
我的tsconfig.json看起来像:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es2015",
"declaration": true
},
"include": [
"static/js/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
您需要在tsconfig.json
中指定"moduleResolution": "node"
选项
如果指定target: "es2015"
,则模块系统将为es2015
。如果模块系统是es2015
,则模块的分辨率默认为clasic
,而不在node_modules
中查找类型(如本文所述(。您可以在编译器选项的文档中找到这一点