-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'src' of img tag become src="[object Module]" in browser #1612
Comments
Workaround: set the It's because in |
Oh...! I see. I'm careless! |
Was this issue fixed and released? I seem to have run into a similar scenario when using rails ( |
Same for me, I've just started a project and v15.9.1 was loaded from repro. My image sources showing |
If you use {
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]',
outputPath: 'static/img',
esModule: false // <- here
}
}
]
} |
For Rails with Vue developer @rails/webpacker: 5.0.1 Add the following line in file /* Fix a bug for file inclusion like <img :src="require()"/> */
environment.loaders.get('file').use.find(item => item.loader === 'file-loader').options.esModule = false before module.exports = environment |
This issue is also present in Nuxt 2.12.0 You can still access the string value through the 'default' property: |
Downgrading to file-loader to ^2.0.0 (which is the version laravel mix depends on) seems to "fix"/prevent the problem as well. |
I spend with this problem 4 hours until I found your solution. (BTW it worked for me for loading fonts and images in SASS files) |
weirdly enough, this simple fix helped on my React project too lol! |
After installing Storybook in my vue app, this same error came up. My fix within chainWebpack inside vue.config.js was to add this.
|
You can also add this to your Vue config: /* vue.config.js */
module.exports = {
chainWebpack: (config) => {
config.module
.rule('vue')
.use('vue-loader')
.tap((options) => {
const transformAssetUrls = options.transformAssetUrls || {}
return {
...options,
transformAssetUrls: {
video: ['src', 'poster'],
source: 'src',
img: 'src',
image: 'xlink:href',
// Add any other pre defined custom asset items
...transformAssetUrls,
},
}
})
// ...
}
} |
Is this a non-issue in Vue 3? |
Is there any update on this bug? that is not a workaround 🤔 |
i need help with this using React |
Version
15.7.2
Reproduction link
https://github.com/zhangwang945/vue-test.git
Steps to reproduce
webpack 4.41, url-loader 3.0.0 .
Clone code https://github.com/zhangwang945/vue-test.git. Then npm run start.
img src="./assets/jinnang.png" become img src="[object Module]"
What is expected?
src="base64 image"
What is actually happening?
src="[object Module]"
Img tag in template will be compiled into: {attrs:{"src":webpack_require(/*! ./assets/jinnang.png */ "./src/assets/jinnang.png"),"alt":""}}
The reult of webpack_require(....) is Object Module ,so it go wrong. Is it right?
Url in css will be compiled into getUrl(webpack_require(/*! ./assets/jinnang.png */ "./src/assets/jinnang.png"),that go well.
The text was updated successfully, but these errors were encountered: