internal json import in a library breaks when importing this library from a served app in nx

Viewed 81

In my library I'm importing a json file which works correctly when running codes from this library (e.g. storybook, linter), but when I'm importing from this library in an app served by nx I get this error:

Cannot find module './example.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

Do I have to add "resolveJsonModule": true, in my tsconfig.json in the app as well? It feels like something that should be resolved in the library.

1 Answers

Add "resolveJsonModule": true to your compiler options

"compilerOptions": {
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true
}
Related