1
votes

I am trying to use log4javascript in a project and I see that the package does have log4javascript.d.ts present in node_modules/log4javascript/ and the package.json does refer to it in the "typings" property but when compiling my project it complains with:

S2307: Cannot find module 'log4javascript'

I am importing the module using:

import {getLogger } from 'log4javascript';

From what I understand one does not need to install typings separately with:

npm install @types/log4javascript

as the typing is already present. But I am not sure how do I use the module types and methods if I have:

"noImplicitAny": true,

set in my tsconfig.json

My tsconfig.json looks like:

{
    "compileOnSave": true,
    "compilerOptions": {
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es2015",
        "declaration": true
    },
    "include": [
        "static/js/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
1

1 Answers

3
votes

You need to specify in your tsconfig.json the "moduleResolution": "node" option

If you specify target: "es2015" then the module system will be es2015. If the module system is es2015 then the resolution for modules defaults to clasic which does not look in node_modules for types (as stated here). You can find this in the docs for the compiler options