最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - IntelliJ Javascript "Cannot Find Declaration to go to" when using custom module path - Stack Overflo

programmeradmin1浏览0评论

I'm trying to use Javascript ES6 import syntax with WebPack configured to use client and node_modules as root paths for resolving imports.

IntelliJ Idea discovers modules from "node_modules" directory, but it cannot resolve paths from "client" directory.

For example:

When im using:

  • import ImmutableStore from 'alt/utils/ImmutableUtil'; - IntelliJ finds proper paths, because alt module is on node_modules directory

  • import CustomiserActions from 'js/actions/Customiser.actions.js'; - It doesn't work, because js module is in client directory.

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

I'm trying to use Javascript ES6 import syntax with WebPack configured to use client and node_modules as root paths for resolving imports.

IntelliJ Idea discovers modules from "node_modules" directory, but it cannot resolve paths from "client" directory.

For example:

When im using:

  • import ImmutableStore from 'alt/utils/ImmutableUtil'; - IntelliJ finds proper paths, because alt module is on node_modules directory

  • import CustomiserActions from 'js/actions/Customiser.actions.js'; - It doesn't work, because js module is in client directory.

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

Share Improve this question edited Oct 14, 2015 at 15:01 Bergi 665k161 gold badges1k silver badges1.5k bronze badges asked Oct 14, 2015 at 14:37 kazkaz 1,9431 gold badge13 silver badges19 bronze badges 1
  • The issue is that IntelliJ does not have a proper support to webpack, check this question stackoverflow.com/questions/31164331/…, they are actively development this feature to the next version of Webstorm, i guess that in a next version of intellj this going to be included. – Jesús Quintana Commented Oct 28, 2015 at 9:48
Add a comment  | 

4 Answers 4

Reset to default 7

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.

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:

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.

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

Make sure *.js extension is listed under JavaScript and absent for Text file types

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论