代码之家  ›  专栏  ›  技术社区  ›  Divick

typescript无法解析类型

  •  1
  • Divick  · 技术社区  · 7 年前

    我试图在项目中使用log4javascript,我发现包的node_modules/log4javascript/中确实存在log4javascript.d.ts,package.json在“typings”属性中引用了它,但在编译我的项目时,它抱怨:

    S2307:找不到模块“log4javascript”

    我正在使用以下方法导入模块:

    import {getLogger } from 'log4javascript';
    

    据我所知,用户无需单独安装打字:

    npm安装@types/log4javascript

    "noImplicitAny": true,
    

    在my 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"
        ]
    }
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   Titian Cernicova-Dragomir    7 年前

    您需要在 tsconfig.json "moduleResolution": "node" 选项

    target: "es2015" 然后,模块系统将 es2015 . 如果模块系统是 es2015 然后,模块的分辨率默认为 clasic 它看起来不在里面 node_modules 对于类型(如所述 here options