Skip to content

Webpack: Reintroduce npm init -y and instruct to remove "type" field #29561

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MaoShizhong
Copy link
Contributor

@MaoShizhong MaoShizhong commented Mar 29, 2025

Because

Original context: #29303 npm v11 introduced a breaking change so npm init always includes a "type" field in package.json, but Webpack can only run a CJS config and bundle ESM at the same time if no "type" field is present in package.json.

#29306 removed the npm init -y instruction since installing a package will make npm auto-create package.json etc. in the project dir.

However, it's been surprisingly very common where people at some point accidentally created a package.json and/or node_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" if package.json contains it (npm LTS still ships with npm v10.9.2 but some people will have manually updated for whatever reason).

This PR

  • Reverts initial commands to include npm init -y
  • Instructs to remove package.json "type" field if present

Issue

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

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

"type" field relevant due to npm v11 and will cause module resolution
clashes with webpack due to mixing the CJS config file and ESM project
source code.

Without `npm init -y`, people often accidentally created a
`package.json` in a parent dir which would cause npm to install there
instead of the real project dir.
@github-actions github-actions bot added the Content: JavaScript Involves the JavaScript course label Mar 29, 2025
@CouchofTomato CouchofTomato requested review from a team and 01zulfi and removed request for a team March 31, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: JavaScript Involves the JavaScript course
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant