I am facing an issue with importing a .json
file in my Angular project. The file is located outside the project structure as shown below:
| common
| configuration.json
| angular-app
| src
| app
| my-component
| my-component.component.ts
| angular.json
Within the my-component.component.ts
file, I have attempted to import configuration.json
using
import configuration from '../../../../common.configuration.json'
. However, Angular keeps throwing the following error:
ERROR in src/app/record/record.component.ts(4,23): error TS2732: Cannot find module '../../../../common/configuration.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
Upon trying ng serve --resolveJsonModule
, I encountered this error message:
Unknown option: '--resolveJsonModule'
Unfortunately, moving the configuration.json
file is not an option as the common
directory is shared with other projects.
How can I successfully import a local json file in an Angular project?