webpack.js.org icon indicating copy to clipboard operation
webpack.js.org copied to clipboard

Inconsistent module syntax in tutorial (ESM `import` vs. CommonJS `require`)

Open Brennvo opened this issue 10 months ago • 4 comments

In the "Getting Started" tutorial section, webpack.config.js is initialized using ESM syntax:

webpack.config.js

import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export default {
  entry: "./src/index.js",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, "dist"),
  },
};

However, in the section that immediately follows ("Asset Management"), CommonJS syntax is used:

webpack.config.js

 const path = require('path');

 module.exports = {
   entry: './src/index.js',
   output: {
-    filename: 'main.js',
+    filename: 'bundle.js',
     path: path.resolve(__dirname, 'dist'),
   },
 };

This can be confusing to somebody who is completing the tutorial sequentially.

Brennvo avatar Feb 02 '26 01:02 Brennvo

PR welcome

alexander-akait avatar Feb 02 '26 15:02 alexander-akait

Hi! I’ve submitted a PR that aligns the Getting Started guide with a CommonJS webpack.config.js example: #7786.

This follows the approach discussed here.
Happy to adjust, rebase, or close it if it overlaps with other changes. Thanks!

the-shreyash avatar Feb 07 '26 07:02 the-shreyash

Hi, I would like to work on aligning the module syntax in the tutorial by using CommonJS consistently across sections. Please let me know if that approach works.

aayushi-tomar avatar Feb 26 '26 15:02 aayushi-tomar

Hi I’d like to work on this issue if it’s still open.
I’ve reviewed the tutorial section and noticed the inconsistency between ESM (import) and CommonJS (require) syntax. I’d be happy to standardize the examples according to the preferred module format used in the documentation.

Please let me know if I can proceed.

PeterWayne12 avatar Mar 02 '26 04:03 PeterWayne12