W
Wasp6mo ago
Flictum

Json support

I'm trying to add lottie animation in my project and even if I provided the option to resolve json file, compilation process keeps failing saying that I need to enable the option. Here my tsconfig:
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
// We're bundling all code in the end so this is the most appropriate option,
// it's also important for autocomplete to work properly.
"moduleResolution": "node",
// JSX support
"jsx": "preserve",
"strict": true,
// Allow default imports.
"esModuleInterop": true,
"resolveJsonModule": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"typeRoots": [
// This is needed to properly support Vitest testing with jest-dom matchers.
// Types for jest-dom are not recognized automatically and Typescript complains
// about missing types e.g. when using `toBeInTheDocument` and other matchers.
"node_modules/@testing-library",
// Specifying type roots overrides the default behavior of looking at the
// node_modules/@types folder so we had to list it explicitly.
// Source 1: https://www.typescriptlang.org/tsconfig#typeRoots
// Source 2: https://github.com/testing-library/jest-dom/issues/546#issuecomment-1889884843
"node_modules/@types"
],
// Since this TS config is used only for IDE support and not for
// compilation, the following directory doesn't exist. We need to specify
// it to prevent this error:
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file
"outDir": ".wasp/phantom"
}
}
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
// We're bundling all code in the end so this is the most appropriate option,
// it's also important for autocomplete to work properly.
"moduleResolution": "node",
// JSX support
"jsx": "preserve",
"strict": true,
// Allow default imports.
"esModuleInterop": true,
"resolveJsonModule": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"typeRoots": [
// This is needed to properly support Vitest testing with jest-dom matchers.
// Types for jest-dom are not recognized automatically and Typescript complains
// about missing types e.g. when using `toBeInTheDocument` and other matchers.
"node_modules/@testing-library",
// Specifying type roots overrides the default behavior of looking at the
// node_modules/@types folder so we had to list it explicitly.
// Source 1: https://www.typescriptlang.org/tsconfig#typeRoots
// Source 2: https://github.com/testing-library/jest-dom/issues/546#issuecomment-1889884843
"node_modules/@types"
],
// Since this TS config is used only for IDE support and not for
// compilation, the following directory doesn't exist. We need to specify
// it to prevent this error:
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file
"outDir": ".wasp/phantom"
}
}
No description
3 Replies
kapa.ai
kapa.ai6mo ago
Hi @Flictum. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I understand your issue. However, currently, Wasp 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. There is an open issue on the Wasp GitHub repository where they are tracking the progress of supporting custom TypeScript configuration. You can follow it here (https://github.com/wasp-lang/wasp/issues/835). Also, there is another open issue about explaining in the docs how to import JSON files / read static files in Wasp on the server. You can check it out here (https://github.com/wasp-lang/wasp/issues/1564). Sorry for the inconvenience. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Flictum, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
martinsos
martinsos6mo ago
Ah yes you can't cusotmize tsconfig yet, that will be coming soon. Check this out though, as bot said: https://github.com/wasp-lang/wasp/issues/1564 Basically bot said it all right!
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...
Flictum
FlictumOP6mo ago
Alright so I will follow the provided answer, thanks for your answer
Want results from more Discord servers?
Add your server