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.

Angular CLI can't find modules from locally installed library.

See original GitHub issue

Versions

Angular CLI: 1.7.4
Node: 7.7.3
OS: darwin x64
Angular: 5.1.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.4.2
webpack: 3.11.0

Repro steps

  • create a library
  • pack it using npm pack
  • install the tgz file using npm install --save path_to_tgz_file
  • run client project

Observed behavior

ERROR in ./src/app/app.module.ts
Module not found: Error: Can't resolve '@my_library/sdk' in '/Users/eestein/Documents/dev/my_library/sdk-front/samples/src/app'
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve '@my_library/sdk' in '/Users/eestein/Documents/dev/my_library/sdk-front/samples/src/app'

Desired behavior

Angular CLI would recognize the local package.

Mention any other details that might be useful (optional)

This is what I have in my package.json of the client project:

"@my_library/sdk": "file:///Users/eestein/Documents/dev/my_library/sdk-front/library/my_library-sdk-1.0.0-alpha.2.tgz",

If I open both offending files (app.component.ts and app.module.ts) in VSCode no error is shown. It looks like VSCode can find it, but Angular CLI can’t.

This is my folder structure:

- library
   - library's code
   - *.tgz file
- samples
    - samples' code
    - package.json referencing the tgz file

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:26 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
maxime1992commented, Jun 11, 2019

@fedealu I’ve been struggling 2 hours with that and it’s finally working.

Maybe this will help you https://github.com/angular/angular-cli/issues/10665#issuecomment-500795466

2reactions
miguelleitevieiracommented, Mar 27, 2019

Hi, I created a library that export some classes used for datamodel. index.ts export * from ‘./lib/user’; export class User { id: number; email: string; name: string; lastAccess: Date; creationDate: Date; }; I made the build of the library and tried to use on my project, but i get an error: ERROR in src/app/@core/helpers/session.manager.ts(9,30): error TS2307: Cannot find module ‘library-data’. Someone know how to fix? I already remove and reinstall packages but did’nt work.

Did you find a solution? I face the same problem. If you fixed it can you please share the solution?

Yes, I created the library using Angular 6. Using that I could import library in Angular 7 projects too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular CLI can't find modules from locally installed library
If I open both offending files ( app.component.ts and app.module.ts ) in VSCode no error is shown. It looks like VSCode can find...
Read more >
Introduction to modules - Angular
You can think of them as library modules. Each Angular library name begins with the @angular prefix. Install them with the node package...
Read more >
Cannot find module '@angular/core' error | bobbyhadz
To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the...
Read more >
Fixing Could not find module @angular-devkit/build-angular ...
Delete node_modules folder and run npm install 2. Install `angular-devkit-build-angular` package as a dev dependency.
Read more >
cannot find module [Node npm Error Solved] - freeCodeCamp
Why the "Error: cannot find module" Occurs · you're trying to import an item from a module you don't have installed in your...
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