Importing a json module

Hello again! One other minor issue I encountered: how can I import a JSON module (import { something } from "./somewhere/my.json";) ? I followed some TS tutorial and enabled esModuleInterop and resolveJsonModule compilerOptions in tsconfig.json but I get a build error in [ Wasp ] TS2732 cannot find module … consider using --resolveJsonModule
2 Replies
Filip
Filip10mo ago
Hi @Šlukas MacPrásk, Wasp unfortunately doesn't support importing JSON directly. You'll have to parse it or convert the file to a regular JS object and import that. As for the tsconfig.json - Yes, that should work, but Wasp unfortunately doesn't yet take the user's tsconfig.json into account when processing code. The tsconfig.json file is only there for the IDE support (as explained by the comment on top of the file). We do plan to improve this though, here's an issue where we keep track of it: https://github.com/wasp-lang/wasp/issues/835 Sorry for the inconvenience
GitHub
Support custom TypeScript configuration · Issue #835 · wasp-lang/wa...
The tsconfig.json files in user source only have effect on IDE support. Our users have no way of configuring the TypeScript compiler, neither for the server nor for the client. We should allow them...
martinsos
martinsos10mo ago
@Šlukas MacPrásk also check this Github issue that links to previous convo on Discord about this, might be helpful: https://github.com/wasp-lang/wasp/issues/1564#issue-1983984672 .
GitHub
Explain in docs how to import JSON files / read static files in Was...
Right now it is a bit tricky because you can directly import .json with node (at least 18), and people get surprised with it because error message is confusing (claims there is no file). I explaine...
Want results from more Discord servers?
Add your server