1

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"
    ]
}
Divick
  • 1,213
  • 1
  • 20
  • 44

1 Answers1

3

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

Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
  • Thanks for your answer. I am wondering when do you use what module system? I am building a project which is to be run in a browser supporting es2015. – Divick Nov 13 '18 at 14:32
  • 1
    @Divick at the moment I'm working on an Angular project and I just use what `ng create` set up for me, which is `"module": "es2015"` with `"moduleResolution": "node"` – Titian Cernicova-Dragomir Nov 13 '18 at 14:38