Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updated getting started guide to correct webpack config file extension to support CJS syntax #7518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RajeevPullat
Copy link

Updated getting started guide to correct webpack config file extension to support CJS syntax

The docs used import statement in index.js which requires setting type: "module". There is a PR raised for the same PR:7516. This PR to correct the webpack config file extension. The CommonJS code won't work in *.js extension and will throw below error.

[webpack-cli] ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension

So its best changed to webpack.config.cjs.

…ension to support CJS syntax

The docs used import statement in index.js which requires setting `type: "module"`. There is a PR for the same `https://github.com/webpack/webpack.js.org/pull/7516`. This is to correct the webpack config file. The commonjs code won't work in *.js extension. So its changed to *.cjs.
Copy link

vercel bot commented Jan 11, 2025

@RajeevPullat is attempting to deploy a commit to the Webpack Docs Team on Vercel.

A member of the Team first needs to authorize it.

@Abhijeet641
Copy link

@RajeevPullat sir, did you fix the lint check ? could you please review my pr once #7513

@@ -237,14 +238,14 @@ As of version 4, webpack doesn't require any configuration, but most projects wi
webpack-demo
|- package.json
|- package-lock.json
+ |- webpack.config.js
+ |- webpack.config.cjs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we provide two examples here - for CommonJS and ECMA modules format?

@@ -271,7 +272,7 @@ cacheable modules 530 KiB
webpack 5.4.0 compiled successfully in 1934 ms
```

T> If a `webpack.config.js` is present, the `webpack` command picks it up by default. We use the `--config` option here only to show that you can pass a configuration of any name. This will be useful for more complex configurations that need to be split into multiple files.
T> By default, if you run the webpack command without specifying a configuration file, Webpack will look for certain default filenames. These typically include: `webpack.config.js` (for CommonJS format in JavaScript), `webpack.config.cjs` (for explicit CommonJS format) or `webpack.config.mjs` (for ES Modules). We use the `--config` option here only to show that you can pass a configuration of any name. This will be useful for more complex configurations that need to be split into multiple files.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants