question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Library that imports JSON file breaks the application build

See original GitHub issue

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

Consuming the library containing a JSON import fails on application build with the following error (library itself is built successfully with both Ivy and ViewEngine):

ERROR in dist/library/public-api.d.ts:1:36 - error TS2307: Cannot find module './example.json' or its corresponding type declarations.

1 export { default as numbers } from './example.json';

Adding "skipLibCheck": true, to tsconfig.base.json silences this error. Ivy built library works fine after that, ViewEngine built library fails with following error:

ERROR in The target entry-point "library" has missing dependencies:
 - ./example.json

How To Reproduce

Checkout the repository: https://github.com/klemenoslaj/ng-package-json-import Execute: yarn && build:lib-ivy - This works fine! Execute: yarn && build:lib-ve - This breaks!


Remove skipLibCheck from tsconfig.base.json to fail for both Ivy and ViewEngine.

Expected Behaviour

Application should successfully compile when consuming a library with imported JSON.

Version Information

ng-packagr:            10.0.3
@angular/compiler:     10.0.5
rollup:                2.22.2
tsickle:               
typescript:            3.9.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
klemenoslajcommented, Aug 15, 2020

I took a quick glance and I saw that you are missing an "resolveJsonModule": true in compilerOptions for tsconfig.base.json

Also, you should never use skipLibCheck.

Are you sure? I am on a phone but i can see the resolveJsonModule in tsconfig.base.json: https://www.github.com/klemenoslaj/ng-package-json-import/tree/master/tsconfig.base.json

0reactions
github-actions[bot]commented, Dec 12, 2020

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

internal json import in a library breaks when ... - Stack Overflow
Have you tried to add a types file to your app ( typings.d.ts )? declare module '*.json' { const value: any; export default...
Read more >
How to Import JSON file as a Module - Bits and Pieces
Learn how to import JSON as a module using Import Assert, a TC39 Stage 3 feature.
Read more >
ng build library doesn't include json files like normal app #11931
I tried out to import the component directly in the app via public_api.ts and it will work. It also build the app including...
Read more >
Working With JSON Data in Python
In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in...
Read more >
Content Types - ESBuild
Imported variables are live bindings to variables in another file. They are not copies of those variables. So when esbuild bundles your code,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found