Parcel - Babel - Vue - Error: Cannot find module `…/…/img.svg`

回眸只為那壹抹淺笑 提交于 2020-12-13 03:35:59

问题


Im a bit in the dark therefore reaching out as I couldnt find a solution or answer. Im using parcel with Vue and trying to import a static image as ../img/logo.svg. This used to work before until I introduced Babel to the mix. Now I get Error: Cannot find module 'img/logo.svg' during runtime. It is weird because in the dist folder I see a logo.svg with a hash. Is it a babel or parcel issue? do I need some extra plugin? or something Im missing?.

Im basically using babel out the box. I just have in my .babelrc

{
 "presets": ["@babel/preset-env"]
}

The file structure goes like this, Im trying to reference logo.svg from Page.vue as import logo from '../img/logo.svg';

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

Thank you so much in advance!

来源:https://stackoverflow.com/questions/63226633/parcel-babel-vue-error-cannot-find-module-img-svg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!