2
votes

I downloaded the package "immutable" from the package manager "npm" and its file "package.json" has a property "typings" with the value node_modules/immutable/dist/immutable.d.ts

The problem is when I try to use it from a class I get the error TS2307 (TS) Cannot find module 'immutable'

import { Immutable } from "immutable"; // error here

export class RestRepository<T = IEntityBase> extends BasicRepository<T>
{
    private c: Immutable.Foo;
}

I understand that theproperty exclude from tsconfig excludes all file inside node_modulesfolder (except node_modules/@typings) but "@typings/immutable" does not have ts files but a readme.md

README.md

This is a stub types definition for Facebook's Immutable (https://github.com/facebook/immutable-js).

Facebook's Immutable provides its own type definitions, so you don't need @types/immutable installed!

Any help would be very appreciated!

- tsc 2.6

1
You don't need installing the definitions because they are already included in the module - look inside immutable/dist and you will find it - and this is clear in the read.md. I tried to compile with a tsconfig with "exclude": ["node_modules"] option and it worked - using tsc 2.6.1. I used VScode 1.18.0 and when I typed some function exposed by the library, the editor imported it automatically. - user8928802
As a sanity check, just try to import some function you are positive that exists in the library like import {Stack} from "immutable"; - user8928802
Hi!, my target is ES6,.. I don't know if my target is the problem... I will try to create a new project and change my target to see if it works. Thanks. - Carlos Huchim
Same issue here - how did you solve this?? - olee

1 Answers

1
votes

I had a similar issue with Immutable. The only way I could fix it was to do the following 3 steps:

1) Copy the immutable.d.ts file to the root of the app which in my case was the same level as my index.ts

2) Import the immutable namespace as you have above (step one prevented this from showing an error)

3) Import the functions I actually wanted to use i.e. Map etc

This left me with the following:

import * as Immutable from "immutable";
import { Map } from "immutable";

Only then could I both get rid of the error on the namespace import (which for me was preventing a release build) and import the actual feature I was attempting to use (Map).