Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Supercharging webpack with Loaders

Image not loading

Can anyone help? I'm not getting any error messages but my image is not rendering. My code is as follows

package.json

{
  "name": "webpack-treehouse-example",
  "version": "0.0.1",
  "scripts": {
    "build": "webpack --optimize-minimize",
    "start": "webpack-dev-server"
  },
  "devDependencies": {
    "babel-core": "^6.23.1",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-2": "^6.11.0",
    "css-loader": "^0.28.7",
    "file-loader": "^0.10.1",
    "html-webpack-plugin": "^2.22.0",
    "img-loader": "^2.0.0",
    "node-sass": "^4.7.2",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.1",
    "url-loader": "^0.5.8",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "jquery": "^3.1.0"
  }
}

webpack.config.js

var HtmlWebpackPlugin = require("html-webpack-plugin");
var path = require('path');

var webpackConfig = {
    entry: "./src/index.js",
    output: {
        path: path.resolve(__dirname, 'build'),
        filename: "build"
    },
    module: {
        loaders: [
            {
                loader: "babel-loader",
                test: /\.js$/
            },
      {
        loaders: ["style-loader", "css-loader", "sass-loader"],
        test: /\.scss$/
      },
      {
                loaders: ["url", "img"],
                test: /\.png$/
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "src/index.ejs"
        })
    ]
};

module.exports = webpackConfig;

styles.scss

.avatar {
    width: 100px;
    height: 100px;
    border-radius: 50px;
    float: left;
    margin-right: 20px;
    background-color: gray;
    background-image: url(/me.png);
    background-size: contain;
}

2 Answers

I know the instructor doesn't have a slash / in front of the url, but my app keeps crashing without the slash. I didn 't see a step where Isaac created a directory for the images. His image is in the root of the src folder.

jaycode : the problem really come from the slash in you url.