3

I am using VS17 Enterprise. I can easily import "typescript-collections" (as instructed on this page) if I had set my module option to commonjs in my tsconfig.json.

However, as soon as I change it to "umd" or "amd", I get error (see the screenshot please) saying that Cannot find module 'typescript-collections' and therefore, the two variables queue and queue1 will be of type any. I have also attached my tsconfig.json.

Any help will be greatly appreciated.

enter image description here enter image description here

Louis
  • 146,715
  • 28
  • 274
  • 320

2 Answers2

0

As of today this problem with this package remains and my solution was to use es6 as my module

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": [],
    "module":"es6"
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

and then import the classes using the notation below -

import * as Collections from 'typescript-collections/src/lib';

It seems there is an issue with this dependency packaging.

Gautam
  • 1,030
  • 13
  • 37
  • even this results in compilation error i.e. index.ts needs to be a part of the package or similar error message. I ended up copying all the classes to my project source folder to use it. – Gautam Apr 16 '19 at 08:21
0

I fixed a similar problem by explicitly specifying the moduleResolution compiler option.

{
    "compilerOptions":
    {
        "moduleResolution": "node"
    }
}

Apparently the moduleResolution is set to "node" automatically, if module is set to "commonjs". The Typescript compiler seems to use another resolution strategy otherwise.

A post in a GitHub issue thread led me to this idea.

Neonit
  • 680
  • 8
  • 27