I am facing an issue with loading a JSON file in my new VueJS project.
Reproduction / Issue
To easily reproduce the issue, I have created a Github repository: https://github.com/devedse/VueJSImportJsonFile
In the Home.vue page, I am trying to get the JSON loading to work. (https://github.com/devedse/VueJSImportJsonFile/blob/master/src/views/Home.vue)
When you open this solution in VSCode, the following line shows an error:
import theJson from '@/assets/hi.json';
https://i.sstatic.net/qvlFk.png
Can't find module '@/assets/hi.json'
When running NPM Serve, the following error pops up: https://i.sstatic.net/OHjp3.png
What I've already tried
I have already searched on Stack Overflow and tried solutions from the following posts:
Importing json file in TypeScript
Typescript compiler error when importing json file
https://github.com/chybie/ts-json
Edit 1:
I have managed to get it to work when running npm run serve
by adding this to the tsconfig.json:
{
"compilerOptions": {
"resolveJsonModule": true
}
}
However, the error in VSCode persists. Is there a way to fix this too?