Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools

Angelic Sanoy
Angelic Sanoy
4,596 Points

[emitted] [immutable] issue: File-loader doesn't generate a img folder in my dist - webpack

Hi

<p>I'm certain that I have run all the necessary plugin and it's already inserted in my .json file but my image is still not loading and there's no folder generated on my dist folder.</p>

<p>Check my terminal result <a href="https://ibb.co/713LzYd"> </a></p>

<p>My local server result</p> <p><a href="https://prnt.sc/X0Jfc4bpTQRp"> Frontpage </a></p>

<p><a href=https://ibb.co/4dMLSmk>DOM </a>- the DOM run the 2nd emitted file not the first one that's why it's showing 404.</p>

When I run my dev, looks like the but it looks like the image but it doesn't inject on my .

My app.common.config.js

//default in webpack but you need to call it to make the path works below. __dirname
const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const loader = require("sass-loader");

// For DEv
module.exports = {
entry: "./src/index.js",
module: {
      rules: [
        {
          test: /\.s[ac]ss$/i,
          use: [
          "style-loader", 
          "css-loader",
          "sass-loader", 
          ]
        }, 
        {
          test: /\.html$/,
          use: ["html-loader"]
        }, 

        {
          test: /\.(svg|png|jpg|gif)$/,
          use: [
            {
              loader: "file-loader",
              options: {
                name: '[name].[hash].[ext]',
          publicPath: 'assets',
          outputPath: 'assets/img',
          esModule: false

              }
            }
          ]
        }
      ]
    },
    plugins: [
      new HtmlWebpackPlugin({
      template: "./src/template.html"
    })
    ]
  };

My app.dev.config.js

const path = require("path");
const { merge } = require('webpack-merge')
const common = require("./app.common.config");



// For DEv
module.exports = merge(common,{
mode: "development",
output: { 
    filename:"main.js",
    path: path.resolve(__dirname, "dist"),
},
});

My package.json

{
  "name": "webpack-project",
  "version": "1.0.0",
  "private": true,
  "description": "Required to run Webpack",
  "main": "index.js",
  "scripts_comment_2": [
    "scripts is used to run your program",
    "you can run two scripts, one for production & one for dev"
  ],
  "scripts": {
    "start": "webpack-dev-server --config app.dev.config.js --open",
    "build": "webpack --config app.prod.config.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^6.7.3",
    "file-loader": "^6.2.0",
    "html-loader": "^4.2.0",
    "html-webpack-plugin": "^5.5.0",
    "sass": "^1.57.1",
    "sass-loader": "^13.2.0",
    "style-loader": "^3.3.1",
    "webpack": "^5.75.0",
    "webpack-cli": "^5.0.1",
    "webpack-dev-server": "^4.11.1",
    "webpack-merge": "^5.8.0"
  },
  "browser": {
    "[module-name]": false
  }
}