Issue
I am currently facing a challenge in my Vue project where I need to import images from the assets folder using a separate Typescript file.
Context
This particular project is set up with vue-cli and utilizes TypeScript version 3.2.1
. I have attempted importing the images directly using both require and import statements, but unfortunately, neither method has been successful.
Attempted Solutions
Here are the methods I have tried:
./src/myFile.ts
import Image from '@/assets/img/hello.png';
No luck
./src/myFile.ts
import Image from '../assets/img/hello.png';
No success
./src/myFile.ts
const Image = require('../assets/img/hello.png');
Still unsuccessful
Outcome
Whenever I try to bundle the files, an error message stating Relative modules were not found
appears indicating a problem with the file path. Even after verifying the correctness of the path, it seems like there might be an issue with how TypeScript handles imports within the Vue-cli configuration.
Visual Reference
Attached below is a screenshot of the project showing the file path as ./src/views/World/Combat/Game.ts
:
https://i.sstatic.net/m7pio.png