Skip to content

"type": "commonjs" is now the default in npm init #1380

@webchick

Description

@webchick

Hello, me again. ;) This time, I'm going through your nice https://docs.apify.com/academy/web-scraping-for-beginners/ course.

At the Setting up your project step, it contains the following directive:

"To switch to the modern version, open your package.json and add this line to the end of the JSON object. Don't forget to add a comma to the end of the previous line 😉"

However, as of NPM 11 / npm/init-package-json#313 (it seems), type is already defined. Here's the default contents of package.json after running npm init -y in 11.0.0:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "type": "commonjs",
  "description": ""
}

If you follow the steps as directed, Visual Studio Code will get mad at you because there are duplicate keys:

Visual Studio Code showing two warnings in the Console due to Duplicate object key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions