Automatic Import Problem

I have a problem with automatic imports.

If i do auto imports the problem is instead of adding an import like:

import {Class} from "B"

Webstorm adds an import like:

import {Class} from "B/types/core/B"

I allways need to remove the /types/core/B manually which is time consuming and prone to error.

 

I have 2 Modules.Module A has module B linked via npm link.

Package JSON Entries of B:

"main": "dist/lib/src/index.js",
"module": "dist/lib/src/index.js",
"typings": "dist/types/src/index.d.ts",

dist/lib/src/index.js is a barrels file which contains this:

export * from "./core/B"

dist/types/src/index.dts looks quite the same:

export * from "./core/B"

 

Any Ideas?

 

1
8 comments

Please can you share a sample project I can use to recreate the issue?

May be related to https://youtrack.jetbrains.com/issue/WEB-30212, but I'm not sure what your project looks like, and "B/types/core/B" doesn't look like relative path

BTW, what WebStorm version do you work with?

0

Here is the Example i am using Webstorm 2018.1

https://github.com/Gr33nbl00d/webstorm-example-imports

 

To reproduce:

.\moduleb\npm run build

on modulea link moduleb with

npm link ..\moduleb

Now if you open the A.ts there is  missing import of B when hitting ALT-ENTER --> Add Import Statements i get:

import {B} from "moduleb/dist/types/src/core/B";

 

 

0

Thanks... When I open module-a folder as a project via File | Open, open A.ts and hit Alt+Enter to import B, I get

 

import { B } from 'moduleb';

export class A {

constructor() {
new B();
}
}

 

What IDE version do you work with? What do your Typescript import preferences (Settings | Editor | Code Style | TypeScript | Imports) look like?

0

Really ok than it might just be some idea/webstorm misconfiguration

I am using Typescript 2.7.2

 

 

 

 

0

Sorry forgot the webstorm version:

WebStorm 2018.1
Build #WS-181.4203.535, built on March 22, 2018

0

May be  https://youtrack.jetbrains.com/issue/WEB-32081 then...

Please try upgrading WebStorm - does the issue persist?

0

Wow thank you so much it is FIXED! YEAHHH No more import corrections:)

I was quite sure this was a configuration problem from my projects not a webstorm problem thats why i didnt try to update :)

 

 

1
Avatar
Permanently deleted user

What did you do to solve it?

0

Please sign in to leave a comment.