question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode Angular 9 Auto-Import for Custom Libraries

See original GitHub issue

TS Template added by @mjbvz

TypeScript Version: 3.8.3

Search Terms

  • angular

I’m currently building an Angular 9 Library using VSCode (version 1.42.1 on MAC OS). I followed the Angular Tutorial on how to create libraries - https://angular.io/guide/creating-libraries.

I also added schematics to the angular package, I’m currently having problems when I add the Library to Angular Application using the ng add ~/projects/my-library-0.01.tgz --save command.

VSCode is unable to auto-import components or classes defined in this package.

Cannot find name ‘MyService’.

If I manually add import { MyService } from 'my-library' this works fines.

Is there a reason why the auto-import is not working for custom angular libraries?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
chrisebejermtcommented, Mar 9, 2020

@marcusingogo, after a number of days searching the web, I found that by adding the following code to the tsconfig.json should resolve the auto-import suggestion.

"typeRoots": [
   "node_modules"
 ]

Can you please try it out and see if it works on your project as well ?

1reaction
marcusingogocommented, Mar 4, 2020

Our dev team (5 people) also has this issue and has had it for sometime across multiple versions of vsc

This is specific to angular libraries, in the same work space auto imports work fine for the app (src/app) but when working in the library (projects/libraryname/src) auto imports comes up with no suggestion

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Code Automatic Imports - typescript
TypeScript Importer works well, also with custom rootDirs or mappings using paths in tsconfig.json . It fixes the broken autoimport of VS Code....
Read more >
Visual Studio Code Extension - Auto Import - YouTube
Visual Studio Code Extension - Auto ImportIn this video, we take a look at the Auto Import extension within Visual Studio Code.
Read more >
Auto Import - Visual Studio Marketplace
Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX. Big thanks ...
Read more >
Enable JavaScript auto-import suggestions in VS Code
As of 2018, VS Code treats all JS files as separate from one another. In order to tell it that your files are...
Read more >
Angular Language Service
In Visual Studio Code, install the extension from the Extensions: Marketplace. Open the marketplace from the editor using the Extensions icon on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found