简体   繁体   English

WebStorm无法识别导入中的index.ts文件

[英]WebStorm not recognising index.ts files in imports

I have a project setup which is using Webpack. 我有一个使用Webpack的项目设置。 I have a few aliases for different directories: 我对不同的目录有一些别名:

alias {
    shared/common: path.join(__dirname, 'src/main/js/publish/shared/common')
    app/common: path.join(__dirname, 'src/main/js/publish/app/common')
}

In some files I would like to import different modules from a single barrel : 在某些文件中,我想从一个桶中导入不同的模块:

import { Comp1, Comp5, Comp7 } from 'shared/common/components';

In order to make that work, inside shared/common/components I created the barrel index.ts file: 为了完成这项工作,我在shared/common/components内部创建了barrel index.ts文件:

import { Comp1 } from '.comp1/comp1.comp';
import { Comp2 } from '.comp2/comp2.comp';
import { Comp3 } from '.comp3/comp3.comp';
....
import { CompN } from '.compN/compN.comp';

export {
    Comp1,
    Comp2,
    Comp3,
    ...
    CompN
}

Although this compiles fine, WebStorm displays an error in the first import saying that it cannot resolve all those symbols. 尽管可以正常编译,但是WebStorm在第一次导入时显示错误,表明它无法解析所有这些符号。

I tried to mark src/main/js/publish as Resource Root, as that's the directory which contains shared and app , but still doesn't work. 我试图将src/main/js/publish标记为Resource Root,因为这是包含sharedapp的目录,但仍然无法正常工作。

It works fine if I change the import to: 如果我将导入更改为:

import { Comp1, Comp5, Comp7 } from 'shared/common/components/index.ts';

Is there any way to make WebStorm recognise those index.ts files without actually writing them in the imports? 有什么方法可以使WebStorm识别这些index.ts文件而无需在导入中实际写入它们?

As @anstarovoyt pointed out in his comment, the problem was fixed after updating to WS2016.2 . 正如@anstarovoyt在他的评论中指出的那样,该问题在更新为WS2016.2之后得以WS2016.2

So it seems that the only two options are either update your WebStorm or keep writing the extension in the imports: 因此,似乎只有两个选项是更新WebStorm或继续在导入中编写扩展名:

import { Comp1, Comp5, Comp7 } from 'shared/common/components/index.ts';

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

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