简体   繁体   English

使用自定义模块路径时,IntelliJ Javascript“找不到到 go 的声明”

[英]IntelliJ Javascript "Cannot Find Declaration to go to" when using custom module path

I'm trying to use Javascript ES6 import syntax with WebPack configured to use client and node_modules as root paths for resolving imports.我正在尝试将 Javascript ES6 导入语法与 WebPack 配置为使用clientnode_modules作为解析导入的根路径。

IntelliJ Idea discovers modules from "node_modules" directory, but it cannot resolve paths from "client" directory. IntelliJ Idea 从“node_modules”目录中发现模块,但无法解析“client”目录中的路径。

For example:例如:

When im using:当我使用时:

  • import ImmutableStore from 'alt/utils/ImmutableUtil'; - IntelliJ finds proper paths, because alt module is on node_modules directory - IntelliJ 找到正确的路径,因为alt模块位于node_modules目录中

  • import CustomiserActions from 'js/actions/Customiser.actions.js'; - It doesn't work, because js module is in client directory. - 它不起作用,因为js模块在client目录中。

I've tried many options in module settings/project settings/marking directory as source roots/adding external libraries but nothing seems to work.我在模块设置/项目设置/标记目录中尝试了许多选项作为源根目录/添加外部库,但似乎没有任何效果。

IntelliJ Idea version: 14.1.5 IntelliJ Idea 版本:14.1.5

I know this is old thread. 我知道这是旧线程。 Just for reference, mark the parent directory(in this case 'js') as 'Resource Root,' then Intellisense will work on 2016 version. 仅供参考,将父目录(在本例中为'js')标记为'Resource Root',然后Intellisense将在2016版本上运行。

What worked for me: 什么对我有用:

File > Invalidate Caches / Restart... 文件>无效缓存/重新启动...

Based on my own experience, IntelliJ will by default search for the source file in the node_modules directory unless it's a relative path like this: 根据我自己的经验,IntelliJ默认会在node_modules目录中搜索源文件,除非它是这样的相对路径:

import CustomiserActions from './js/actions/Customiser.actions.js';

Depending on how your project is structured/build, this might be a solution to your problem. 根据项目的结构/构建方式,这可能是您的问题的解决方案。

In my case I had a Javascript project and *.js files was not recognized as a javascript file (Note the icon with JS) but rather as a text file.在我的例子中,我有一个 Javascript 项目,*.js 文件没有被识别为 javascript 文件(注意带有 JS 的图标),而是一个文本文件。

IntelliJ -> Preferences... -> Editor -> File Types

Make sure *.js extension is listed under JavaScript and absent for Text file types确保 *.js 扩展名列在JavaScript下,文本文件类型不存在

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

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