1

I've an angular application a-app in 10.0.6, but I need to include it into an angular multi-project structure. In this multi-project structure, I have a b-app application.

  • Angular multi-project structure is working fine.
  • I have created a my-lib library and included it into b-app application and it's working. I followed this procedure Using your own library in applications
  • I moved my a-app application into the multi-project structure and it's working! To make this work, I'm using the package.json, tsconfig.json, tsconfig.base.json, angular.json from multiproject structure. And tsconfig.app.json and tsconfig.spec.json extends ../../tsconfig.base.json.
  • It means, I can run both applications a-app and b-app from multi-project structure.

Folder structure is this:

my-workspace/
  ...             (workspace-wide config files)
  projects/       (generated applications and libraries)
    a-app/        --(imported application manually)
      ...         --(application-specific config: karma.conf.js, tsconfig.app.json, tsconfig.spec.json)
      src/        --(source and support files for application)
    b-app/ --(an explicitly generated application)
      ...         --(application-specific config)
      src/        --(source and support files for application)
    my-lib/       --(a generated library)
      ...         --(library-specific config)
      src/        --source and support files for library)

But when I try to import my-lib in application a-app in the multi-project structure, it's not working!!! Just displays this error:

  • Cannot find module 'my-lib' or its corresponding type declarations

I've modified all config files from a-app to be similar to b-app, included the a-app in the angular.json, but still not working. Practically, I did steps 3-5 from here: Adding Angular application to an existing project

What am I missing in this configuration, to make it work?

4
  • Just a suggestion: try using NX. Angular workspaces have their limitations. For example, you cannot reference a library from another library, etc. Commented Dec 14, 2021 at 20:46
  • Thanks man, I'll take a look on it. Commented Dec 14, 2021 at 21:19
  • Here's an example workspace containing a yourube-api and youtube-player library + demo application. Commented Dec 14, 2021 at 21:24
  • 1
    Also another note: use the same major version number for your package as the angular version you're targetting. Eg. If your library uses @angular/core: ^12.1.3 then give your library a version 12.x.x. Commented Dec 14, 2021 at 21:29

1 Answer 1

1

Well... It was a mistake.

I'm using Path mapping in a-app application which means that I had configured the paths property in tsconfig.app.json inside a-app.

With that configuration, the a-app didn't extend the paths property in tsconfig.base.json, therefore, it couldn't find the my-lib path declared on this file.

Solution: remove/check any configuration in your paths in tsconfig.app.json to extend properly the tsconfig.base.json

my-workspace/
  tsconfig.base.json <--- this file contains all libraries declared
  projects/       
    a-app/        
      tsconfig.app.json <--- Check this file in order to extend properly the tsconfig.base.json
    b-app/
      tsconfig.app.json
    my-lib/
      ...
      src/
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.