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

166
Views
Unable to load image using Webpack 5

I'm using webpack 5 to bundle an embeddable widget. I can't seem to load an image created on the fly.

const img = document.createElement('img');
img.src = 'assets/doggo.svg';

http://localhost:8080/assets/doggo.svg gives 404

In my webpack.config.js I have the following:

module: {
         rules: [
            // Typecript
            {
               test: /\.ts|\.tsx$/,
               use: 'awesome-typescript-loader',
               include: __dirname
            },
            // Images
            {
               test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
               type: 'asset/resource',
            },
            // Fonts and SVGs
            {
               test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
               type: 'asset/inline',
            },
         ],
      },

Below is my file structure:

├── package.json
├── postcss.config.js
├── src
│   ├── index.ts
│   ├── assets
│   ├── index.html
│   ├── index.ts
│   ├── types.d.ts
│   └── utils
├── tsconfig.json
├── webpack.config.js
└── yarn.lock
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The approach below seems to work.

import doggoImg from './assets/doggo.svg';

const img = document.createElement('img');
img.src = doggoImg;

const container = document.createElement('div');

container.appendChild(img);

about 4 years ago · Santiago Gelvez 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!