3

I'm writing an angular cli 16.2.0 project and i encounter the following problem:

i created a workspace, lets call it test

# ng new test --no-create-application

i created a library project called foo and an application project called foo-app using the cli.

# ng g application foo-app
# ng g library foo

then i created a module foofoo in project foo:

#  ng generate module foofoo --project foo

now i want in my foo-app project to be able to require modules from the @audiotext workspace project, in this case the module foofoo, and i want to do that by typing @foo/module_name

so in this case i want this to work:

import('@foo/foofoo');

I tried to add to paths section of the main tsconfig.json or the foo-app/tsconfig.app.json:

"paths": {
      "@foo/*": ["projects/foo/*"]
    },

or

"paths": {
      "@foo/*": ["projects/src/public_api"]
    },

i also tried adding

"declarations": ["./src/public_api.ts"]

to tsconfig.lib.json of the foo library project

but the results are the same. it can't resolve @foo.

i feel like i'm shooting in the dark here, just trying things that i google till one thing will work.

any ideas what am i missing ?

ufk
  • 30,912
  • 70
  • 235
  • 386
  • are you trying to reference another workspace @audiotext? you can't do that. in angular you can reference only the same workspace. if you have other projects, you need to publish and use them as a dependency. for development purpose you can use `npm link` to reference another repo. but that is only for development so you won't have to keep publishing. – SO is full of Monkeys Aug 20 '23 at 04:34
  • @SOisfullofMonkeys - it's in the same workspace, it's a library project in that same project. i literally created an example and showed every step in the description and i know it's possible because i'm updating an angular 10 project and it was like that there – ufk Aug 20 '23 at 16:05
  • yeah it must be something else. your setting seems correct. i don't see why, sorry! – SO is full of Monkeys Aug 21 '23 at 13:15
  • Afaik you can't define the paths in the tsconfig of your app to point to uncompiled code outside of the code that is "managed" by this tsconfig because tsc would not consider the libraries' code for compilation. I wonder how this worked before with your Angular 10 project. My suggestion would be to follow @SOisfullofMonkeys advice and to build the library and use `npm link` to make it available to your application. – Tim Aug 23 '23 at 09:09
  • One idea: You could try to set the rootDirs accordingly to include your library projects too: https://www.typescriptlang.org/tsconfig#rootDirs – Tim Aug 23 '23 at 09:15

0 Answers0