angularangular-libraryangular12

Angular library - Module not found: Error: Cannot resolve module


I have the simples example:

  1. I create Angular library inside workspace from official documentation:
ng new workspace-test --create-application=false
cd workspace-test
ng generate library lib-test
  1. Then I build library and I create npm link for it from ./dist/lib-test directory:
ng build lib-test
npm link
  1. Then I create simplest angular application:
ng new app-test
  1. Now I link my application to the library:
npm link lib-test
  1. When I try to use library inside my app, I get exception
 Error: Module not found: Error: Can't resolve '../../../workspace-test/dist/lib-test/lib/lib-test.component' in 'C:\dev\app-test\src\app'
  1. My usage of the library in the app:
import { LibTestModule } from '../../../workspace-test/dest/lib-test'


...


imports: [
   LibTestModule ,

I don't have idea what is going on, how to make it work? It basic example.


Solution

  • if you want to use local library in another local project then your library build should be inside project's node_modules folder

    solution change the library build destination to the project's node_modules