Is a package.json file missing dependencies?

Curious about the meaning of peerDependencies, I examined the contents of this package.json file. It relates to a library project that is distributed elsewhere.

{
    "name": "...",
    "version": "...",
    "description": "...",
    "author": "...",
    "license": "Unlicense",
    "main": "dist/index.js",
    "typings": "dist/index.d.ts",
    "scripts": {
      "build": "typings install && tsc --outDir dist/"
    },
    "peerDependencies": {
        "@angular/core": "^2.0.0",   <<<<<<<<
        "@angular/http": "^2.0.0",   <<<<<<<<
        "@angular/common": "^2.0.0",   <<<<<<<<
        "@angular/compiler": "^2.0.0",   <<<<<<<<
        "core-js": "^2.4.0",   <<<<<<<<
        "reflect-metadata": "^0.1.3",   <<<<<<<<
        "rxjs": "5.0.0-beta.12",   <<<<<<<<
        "zone.js": "^0.6.17"   <<<<<<<<
      },
      "devDependencies": {
        "@angular/core": "^2.0.0",   <<<<<<<<
        "@angular/http": "^2.0.0",   <<<<<<<<
        "@angular/common": "^2.0.0",   <<<<<<<<
        "@angular/compiler": "^2.0.0",
        "@angular/platform-browser": "^2.0.0",   <<<<<<<<
        "core-js": "^2.4.0",   <<<<<<<<
        "reflect-metadata": "^0.1.3",   <<<<<<<<
        "rxjs": "5.0.0-beta.12",   <<<<<<<<
        "zone.js": "^0.6.17",   <<<<<<<<
        "typescript": "^2.0.0",
        "typings": "^1.3.2"
      }
}
  1. Why is the same package listed in both devDependencies and peerDependencies?
  2. Why isn't dependencies used here?

Answer №1

Starting from npm 3, peerDependencies are no longer automatically fetched when installing a package. Instead, npm will now issue a warning if a dependency is missing.

The rationale behind organizing a package.json in this way could be:

  • Developers working on this package are required to install the dependencies listed under devDependencies.

  • Users utilizing this package may not need to download the dependencies if they already exist in their project. However, in case they do not have them installed yet, the inclusion of peerDependencies ensures that they receive a warning during installation (which they would then have to resolve manually).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There appears to be an issue with the compilation of the TypeScript "import { myVar }" syntax in a Node/CommonJS/ES5 application

In my Node application, I have a configuration file that exports some settings as an object like this: // config.js export var config = { serverPort: 8080 } Within another module, I import these settings and try to access the serverPort property: // ...

The node-gyp configuration encountered an error with the message: "Failed to spawn EPERM at VisualStudio

C:\Users\Jenny_Hung\test\d-api>node-gyp configure gyp info it worked if it ends with ok gyp info using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f997969d9cd49e8089b9c0d7cad7c8">[email protect ...

Troubleshooting TypeScript errors in a personalized Material UI 5 theme

In our codebase, we utilize a palette.ts file to store all color properties within the palette variable. This file is then imported into themeProvider.tsx and used accordingly. However, we are encountering a typescript error related to custom properties as ...

What makes running the 'rimraf dist' command in a build script essential?

Why would the "rimraf dist" command be used in the build script of a package.json file? "scripts": { "build": "rimraf dist ..." }, ...

Having trouble with the Aurelia JSPM install -y command not functioning properly on Windows

I am currently following the Aurelia tutorial at I am attempting to install Aurelia dependencies using Gulp and JSPM. I successfully ran "jspm install -y" without any issues. However, upon opening the browser console, I encountered the following error: ...

Working with arrow functions in TypeScript syntax

I came across the following code snippet in TypeScript: (() => { const abc = 'blabla'; ... })(); Can someone explain what exactly this syntax means? I understand arrow functions in JS, so I get this: () => { const abc = &apos ...

Knowing the appropriate times to utilize the `--force` and `--legacy-peer-deps` flags within npm

Trying to wrap my head around the process of recreating the node_modules directory for deployment. We opt for npm ci over npm install to ensure a clean slate during deployment. But running it without any flags throws an error: Resolve upstream dependenc ...

What is the best time to increase the package version in a continuous integration and continuous delivery (CI/CD) pipeline

I'm currently in the process of setting up a Jenkins pipeline for building and publishing an npm package. One issue I'm facing is deciding when to update the version of the package in the package.json file. If the version is incremented with ever ...

The npm karma phantomJS error message indicates that the undefined object is not a valid

During testing of a react-redux application using Karma, all tests were successful when run with webkit but failed when run with phantomJS. The error message displayed was: TypeError: undefined is not a constructor (evaluating 'Object.assign({} [...] ...

The type 'ClassA<{ id: number; name: string; }>' cannot be assigned to the type 'ClassA<Record<string, any>>'

One requirement I have is to limit the value type of ClassA to objects only. It should also allow users to pass their own object type as a generic type. This can be achieved using Record<string, any> or { [key: string]: any }. Everything seems to be ...

React-router-sitemap lacks a definition for 'Require'

According to the official documentation here, this is how the sitemap-builder.js file should be structured: require('babel-register'); const router = require('./router').default; const Sitemap = require('../').default; ( ...

What is the reasoning behind not allowing an empty object as the initial value for hooks?

I am encountering an issue with my setProd Hooks. export interface faceProduct { readonly title: string; readonly prodState: string; readonly shipping: string; readonly sold: string; readonly alt: string; readonly material: string; readonly ...

Retrieve: Type 'string | undefined' does not match the parameter type 'RequestInfo'

When using the fetch function, I encountered an error with the "fetchUrl" argument: Error: Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'. This is the code snippet where the error occurred: ...

Leverage node-video-lib alongside buffer functionality

I'm exploring how to utilize the library node-video-lib for retrieving information about a video received on the server. However, the documentation only provides examples of working with files from the file system: Here is an example from the documen ...

I am unable to view the most recent version of json-parse-better-errors on NPM

I've encountered an issue while trying to execute the npx create-react-app command on my local machine. The script fails during the installation process of json-parse-better-errors. It seems like it is looking for version 1.0.2, which is stated as the ...

How should one go about creating and revoking a blob in React's useEffect function?

Consider this scenario: import { useEffect, useState, type ReactElement } from 'react'; async function getImage(): Promise<Blob> { // Some random async code const res = await fetch('https://picsum.photos/200'); const blob = ...

Creating an Object Type from a String Union Type in TypeScript

How can I go about implementing this? type ActionNames = 'init' | 'reset'; type UnionToObj<U> = {/* SOLUTION NEEDED HERE */} type Result = UnionToObj<ActionNames>; // Expected type for Result: `{ init: any, reset: any }` ...

What could be causing my sinon test to time out instead of throwing an error?

Here is the code snippet being tested: function timeout(): Promise<NodeJS.Timeout> { return new Promise(resolve => setTimeout(resolve, 0)); } async function router(publish: Publish): Promise<void> => { await timeout(); publish(&ap ...

shortcut taken in inferring now exported

When using a default export, if the expression consists only of a variable identifier, the type inferencer defaults to the declaration of the variable instead of the actual type of the expression. Is this behavior intentional or is it a bug? // b.ts const ...

The POST requests on Next JS Mock API endpoints include parameters passed in the req.body

I am currently running Next JS API tests using jest with a custom testClient. The code for the testClient is as follows: import { createServer } from 'http'; import type { NextApiHandler } from 'next'; import type { __ApiPreviewProps } ...