简体   繁体   English

打字稿错误在 tsconfig.json 中将模块更改为“umd”或“amd”时找不到模块“typescript-Collections”

[英]Typescript error Cannot find module 'typescript-Collections' when changing the module to “umd” or “amd” in tsconfig.json

I am using VS17 Enterprise.我正在使用 VS17 企业版。 I can easily import " typescript-collections " (as instructed on this page) if I had set my module option to commonjs in my tsconfig.json .我可以很容易地导入“打字稿的集合”(可按本网页上),如果我有我的设置module选项commonjs在我的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 .但是,一旦我将其更改为"umd""amd" ,我就会收到错误消息(请参见屏幕截图)说Cannot find module 'typescript-collections'因此,两个变量queuequeue1的类型为any . I have also attached my tsconfig.json .我还附上了我的tsconfig.json

Any help will be greatly appreciated.任何帮助将不胜感激。

在此处输入图片说明 在此处输入图片说明

As of today this problem with this package remains and my solution was to use es6 as my module截至今天,这个包的问题仍然存在,我的解决方案是使用 es6 作为我的模块

{
  "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.这个依赖包似乎有问题。

I fixed a similar problem by explicitly specifying the moduleResolution compiler option.我通过显式指定moduleResolution编译器选项解决了类似的问题。

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

Apparently the moduleResolution is set to "node" automatically, if module is set to "commonjs" .显然moduleResolution被设置为"node"自动,如果module被设置为"commonjs" The Typescript compiler seems to use another resolution strategy otherwise.否则,Typescript 编译器似乎使用另一种解析策略。

A post in a GitHub issue thread led me to this idea. GitHub 问题线程中的一个帖子让我想到了这个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM