Read Json file inside Angular custom library

254 Views Asked by At

I am trying to build a custom library in angular 8. I am trying to read data from a JSON file inside the angular library working file but when I build the library and using in the project the JSON file path is not correct.

enter image description here

when I am using this library inside the project I am getting error like below

ERROR in ./node_modules/chatbot-lib/fesm2015/chatbot-lib.js Module not found: Error: Can't resolve 'projects/chatbot-lib/src/assets/Loc.json' in 'D:\demo\DemoApplication\XmppConnection\node_modules\chatbot-lib\fesm2015'

Also, can someone help me in adding global SCSS in the angular library?

1

There are 1 best solutions below

0
On

your project looks like a monorepo. if it is, try to specify external path alias to tsconfig in compilerOptions.paths

{
  compilerOptions: {
    ...
    paths: {
      "@chatbot": ["projects/chatbot-lib/index.ts"], // <RELATIVE_PATH>
      "@chatbot/assets": ["projects/chatbot-lib/src/assets/index.ts"]
    }
  }
}