Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Img element from Vue.js component is not rendered into Laravel production environment

I am compiling an img element for production with npm run prod from resources/images dir. The compilation is done with webpack.mix.js:

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css').vue();

Bottom of welcome.blade.php:

<body id="body">
  <div id="app">
    <app></app>
  </div>
</body>
<script src="{{ mix('js/app.js') }}"></script>
</html>

The img element is inside a vue component:

  <img :src="require('../images/portrait.png')" id="portrait" alt="">

and gets compiled to public/images dir:

enter image description here

As you can see portrait.png is compiled into public/images. But as soon as I try to run the app with php artisan serve the image is not displayed in the browser. It is the only image not displayed. The browser console shows:

Failed to load resource: the server responded with a status of 404 (Not Found)

on initial page load and:

GET http://127.0.0.1:8000/require(%60../images/portrait.png%60) 404 (Not Found)

on page refresh.

According to this img src thread on github require should work for img elements but it doesn't. Any workaround?

specs:

OS: Windows 10
Vue.js: 4.5.13
Laravel: 8.55.0
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There seems to be an issue with resolving the image as module. Could you try adding .default to the require statement?, e.g.

<img :src="require('../images/portrait.png').default" id="portrait" alt="">

Reference: https://github.com/JeffreyWay/laravel-mix/issues/2756

about 4 years ago · Juan Pablo Isaza Report

0

Can you just use <img src="images/portrait.png" id="portrait" alt=""> ?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!