Import relative to package.json or local module name in WebStorm



I'm trying to import a local component, but in the import I want to use it:

import Icon from 'AppName/styles/Icons';

instead of:

import Icon from '../../styles/Icons';

or instead of

import Icon from 'styles/Icons';

how can I do this, I've searched a lot, but didn't find something useful.

Comment actions Permalink

Is AppName your project name? then no, this can't be done... there is no way to set a prefix for the root path - aliases can only be set for subfolders (using webpack config, or via a workaround from


Generating paths relative to project root is possible with Use paths relative to the project, resource or sources roots option (Settings | Editor | Code Style | JavaScript | Imports)

Comment actions Permalink

Yes AppName is the name that is on my package.json


Please sign in to leave a comment.