WebStorm (2021.3) auto-completion and auto-import not working properly

Viewed 337

I have created two TypeScript projects: one is a library (named "ts-boot") and the other one is the main project ("ts-server") consuming the library. During development I use npm link to automatically fetch code changes.

The code is running fine, but WebStorm IDE (2021.3) has some problems.

The main problem is, that auto-completion for updated code works only after restarting the IDE. After auto-completion works it still does not add the import statement. And after adding it manually it is underlined red saying "TS2307: Cannot find module '...' or its corresponding type declarations.". tsc and node do not complain and the code runs fine.

Autocompletion does not add import

Imports are underlined with error Module not found

In WebStorm I marked node_modules/ts-boot as included to add it to the index.

I'm confused where WebStorm gets its information about what modules to auto-complete and import. I have been struggling with this problem for days and can't find any solution.

Important to me is that I want to keep the long path in the import statement. Many projects use one large declaration file with all the exports in it, but that may lead to name collisions in bigger projects.

tsconfig of "ts-boot":

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./lib",
    "noImplicitAny": true,
    "esModuleInterop": true,
    "strict": true,
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node",
    "declaration": true
  },
  "include": [
    "./src/**/*.ts",
    "./src/**.d.ts",
    "./node_modules/@types/**/*.d.ts"
  ],
  "exclude": [
  ]
}

tsconfig of "ts-server":

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es6",
    "module": "commonjs",
    "rootDir": "./src",
    "outDir": "./target",
    "esModuleInterop": true,
    "strict": true,
    "declaration": true,
    "strictPropertyInitialization": false
  },
  "include": [
    "./src/**/*",
  ],
  "exclude": [
  ]
}

Any help is appreciated! Happy holidays in advance!

Edit 1:

node_modules/ts-boot/lib contains a .d.ts file for each .ts file:

enter image description here

tsc -p . in the root of ts-server runs without errors:

xxx@xxx:~/Documents/projects/dev/workspace/js/ts-server$ npm run build

> ts-server@1.0.0 build
> tsc -p .

xxx@xxx:~/Documents/projects/dev/workspace/js/ts-server$
0 Answers
Related