简体   繁体   English

WebStorm 无法解析导入语句

[英]WebStorm fails to resolve import statement

I have a React Native project that uses package.config files in subdirectories to provide a name.我有一个 React Native 项目,它使用子目录中的 package.config 文件来提供名称。 eg { 'name': '@subdirectory' } .例如{ 'name': '@subdirectory' }

Then, when importing in other files, we see import foo from '@subdirectory/bar' .然后,在其他文件中导入时,我们看到import foo from '@subdirectory/bar'

How do I configure WebStorm 2017.2.2 to accept these alias, rather than giving me 'Module not installed...'?如何配置 WebStorm 2017.2.2 以接受这些别名,而不是给我“未安装模块...”?

您可以尝试在项目视图中右键单击您的子目录,然后-> Mark directory as -> Resource Root

WebStorm provides no support for this React native hack (not officially documented anywhere, as far as I can tell). WebStorm 不提供对这种 React Native hack 的支持(据我所知,在任何地方都没有正式记录)。 If you miss this feature, please follow WEB-23221 for updates.如果您错过了此功能,请关注WEB-23221进行更新。

Marking a parent folder of @subdirectory as Resource root (note: not the subdirectory itself, but its parent dir!) should help to work out the issue.@subdirectory的父文件夹标记为资源根目录(注意:不是子目录本身,而是其父目录!)应该有助于解决问题。

It's just a workaround, but you can create a file with any_name.js along the project root directory with the following content:这只是一种解决方法,但您可以在项目根目录中创建一个包含any_name.js的文件,其中包含以下内容:

System.config({ "paths": { 
       "@subdirectory/*": "./path/to/subdirectory/*"
      }
});

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

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