Webpack: Reintroduce npm init -y
and instruct to remove "type"
field
#29561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Because
Original context: #29303 npm v11 introduced a breaking change so
npm init
always includes a"type"
field inpackage.json
, but Webpack can only run a CJS config and bundle ESM at the same time if no"type"
field is present inpackage.json
.#29306 removed the
npm init -y
instruction since installing a package will make npm auto-createpackage.json
etc. in the project dir.However, it's been surprisingly very common where people at some point accidentally created a
package.json
and/ornode_modules/
in a parent dir e.g.~
, forget or don't realise those files/dirs need deleting, which then causes npm to search upwards and install packages there, confusing learners.Therefore, it would be better for now to reintroduce
npm init -y
to force npm to install packages in the real project dir, and instruct learners to remove"type"
ifpackage.json
contains it (npm LTS still ships with npm v10.9.2 but some people will have manually updated for whatever reason).This PR
npm init -y
package.json
"type"
field if presentIssue
Related to #29303
Additional Information
When Node LTS starts shipping with npm v11.X, I'll explore a proposal to shift the Webpack lessons to full ESM. It would simplify some things, but some challenges include clashes with Webpack docs which use CJS. Mainly relevant in "Revisiting Webpack" where the webpack-merge guide is full CJS.
Pull Request Requirements
location of change: brief description of change
format, e.g.Intro to HTML and CSS lesson: Fix link text
Because
section summarizes the reason for this PRThis PR
section has a bullet point list describing the changes in this PRIssue
section