0

I'm trying to import an image in vue using parcel :

import logo from '../img/logo.svg'; from Page.vue.

Paths are correct.

The error is always the same : cannot find module ../img/logo.svg.

In the dist folder I can see the images hashed.

Im loosing my mind :(

src
 ┣ components
 ┃ ┣ Component.vue
 ┣ css
 ┃ ┗ css.css
 ┣ img
 ┃ ┣ logo.svg
 ┃ 
 ┣ pages
 ┃ ┗ Page.vue
 ┣ index.html
 ┗ main.js
.babelrc

Namysh
  • 3,717
  • 2
  • 9
  • 17
Ehs
  • 39
  • 7
  • Why you want to import this image ? – Namysh Aug 05 '20 at 12:27
  • @Namysh because I want to do some dynamic stuff, i.e: logo: variable ? logo : logo2 – Ehs Aug 05 '20 at 12:33
  • I don't think you can import an image like this, you should use the `Image` object with the source of you image. Like `const logo = new Image(); logo.src = "url"` – Namysh Aug 05 '20 at 12:37
  • @Namysh pretty sure you can, similar as in React https://parceljs.org/module_resolution.html – Ehs Aug 05 '20 at 12:39
  • Ok my bad I can't help you there, sorry and good luck (have you tried absolute path ?) – Namysh Aug 05 '20 at 12:42
  • I am sorry to see that you are still struggling with this [issue](https://stackoverflow.com/questions/63226633/parcel-babel-vue-error-cannot-find-module-img-svg#comment111809703_63226633), @Ehs. What has changed from then till now? Are you still using babel? – Tony Aug 05 '20 at 13:08
  • @Tony not much still using it, I think it is a parcel issue but no luck finding anything, I think I will give up and move to vue-cli or rollup or webpack or anything else :( – Ehs Aug 05 '20 at 13:35
  • Hi, @Ehs, does [this](https://stackoverflow.com/a/58712521/7499991) help you? – Tony Aug 05 '20 at 16:15

0 Answers0