Webpack: Compilation error when going through the Getting Started tutorial

Getting a compilation error when following the Webpack tutorial at https://webpack.js.org/guides/getting-started/.

I’ve gone through it three times now, one time where I typed everything in manually to avoid any hidden characters from copy-paste.

Running on Powershell on Windows 10, Npm version 8.3.0, Lodash version 4.17.21, Webpack version 5.66.0, Webpack-cli version 4.9.1.

The error message is this:

(base) PS C:pathtowebpack-demo> npx webpack
assets by status 291 bytes [cached] 1 asset
./src/index.js 458 bytes [built] [code generated] [1 error]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value.
Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.

ERROR in ./src/index.js 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are confi
gured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

webpack 5.66.0 compiled with 1 error and 1 warning in 196 ms

I’ll paste in the lines of code I have here, but they should be identical to what’s in the tutorial.


<!DOCTYPE html>
    <meta charset="uft-8" />
    <title>Getting Started </title>
    <script src="main.js"></script>


import _ from 'lodash';

function component {
  const element = document.createElement('div');

  element.innerHTML = _.join(['Hello', 'webpack'], ' ');

  return element;



  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^5.66.0",
    "webpack-cli": "^4.9.1"
  "dependencies": {
    "lodash": "^4.17.21"