Dependencies exclusively for NPM post-installUnique Rewrite: "N

I have been using git to distribute an internal TypeScript NPM package. To avoid cluttering my repository with build files, I have implemented a postinstall action to build the package upon installation:

"postinstall": "tsc -p tsconfig.json"

In order to successfully build the package, certain dependencies (such as TypeScript) are necessary. However, including them as dev dependencies means they are not accessible during the postinstall phase, forcing me to declare them as regular dependencies.

My queries regarding this setup are:

  • Are there any disadvantages to specifying these build dependencies as regular dependencies in my package.json file?
  • If so, what is the recommended method for designating build-only dependencies in NPM packages installed via git?

Answer №1

I must express my strong opposition to zamber's viewpoint. There are significant drawbacks to defining all dependencies as production dependencies. By doing so, every person who installs your package will also be installing all of your development dependencies in their node_modules directory. While this may not seem problematic now, just think about the implications if everyone took this approach. Let's not forget that it's not just individuals installing your project; it's also those installing any dependency that utilizes your project.

The node_modules directories are already quite large, and npm install already consumes a considerable amount of time. If everyone were to include development dependencies as production dependencies, the demands on bandwidth, processing power, and hard disk space would skyrocket.

In many of my projects, there are only a few essential dependencies but numerous large development dependencies: tools for building (e.g., TypeScript), testing frameworks like Jest or Jasmine, code linting tools, and even entire web browsers for automation tests. These dependencies are strictly for internal use and should not impose time and storage burdens on others.

The recommended practice for publishing TypeScript libraries is to build before publishing. This ensures that none of the development dependencies are necessary.

Answer №2

Is it a potential issue to list these build dependencies as regular dependencies in my package.json file?

I believe not. These dependencies are necessary for building the package, so there's no way around including them unless you want to commit pre-built files.

Alternatively, you could choose to only provide the source files and leave the building process to your users.

Another approach is to create a separate branch for built files. Keep your source files on the main branch (like master) and have a branch for distribution (like dist). Whenever ready to release, merge master into dist, build, commit, and push. This method gives you more control over updates and simplifies things for users.

It's generally acceptable to store artifacts in your repository if you're developing a library intended for use in other projects. It saves time and effort for those consuming your library.

One drawback of this approach is that users might end up overriding your build dependencies using selective version resolutions in their own package.json files.

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

Encountered an issue with ionViewDidLoad: The property 'firstChild' cannot be read as it is null

While working on an Ionic 2 App with Angular2 and Typescript, I encountered an issue when trying to pass a JSON to map for markers. Here is the link to the gist containing the code snippet I am facing an error that reads: view-controller.js:231 MapPage i ...

Transitioning a GitHub repository to an organization: Handling NPM and Bower registry entries

I am looking to consolidate my projects on GitHub under a new organization, but I have already registered them on both NPM and Bower. How can I avoid or reduce any disruptions for projects that are currently using these dependencies from NPM/Bower? ...

Is the NPM package located in the /node_modules directory but still unable to be located?

I am encountering an issue while attempting to properly install the md5 node module on a Ubuntu development server that I have configured. (The installation works smoothly on my local Windows machine, and I can successfully install other modules using npm ...

Nextjs doesn't render the default JSX for a boolean state on the server side

I am working on a basic nextjs page to display a Post. Everything is functioning smoothly and nextjs is rendering the entire page server side for optimal SEO performance. However, I have decided to introduce an edit mode using a boolean state: const PostPa ...

The Angular service successfully provides a value, yet it fails to appear on the webpage

Currently, I am starting to dive into Angular from the ground up. One of my recent tasks involved creating a component called 'mylink' along with a corresponding service. In my attempt to retrieve a string value from the service using 'obse ...

Passing a complex variable type in TypeScript to a function without the need to redefine the type

I'm fairly new to working with TypeScript and I've encountered this issue several times. When using tools like Prisma to retrieve data, I often come across values with incredibly complex types. These values contain many attributes, which is perf ...

MQTT: The method net.createConnection does not exist

Following the guide at https://www.npmjs.com/package/mqtt#install to establish an mqtt connection, I encountered a render error indicating _$$_REQUIRE_(dependencyMap[1], "net").createConnection(port, host)','_$$_REQUIRE(_dependencyMap[ ...

Tips for adding a mat-error to a mat-input-field on-the-fly

To handle user input exceeding maxLength and dynamically add < mat-error > to the DOM in case of an error, I have implemented an attribute directive that enforces the character limit on input fields. This directive is used across multiple files in th ...

Screen remains blank as the React webpage fails to load

Hello, I am having issues with my React page not showing up. Can someone please review my code to see if there are any errors? Here is the edited program: index.html <!doctype html> <html lang="en"> <head> <meta charset ...

Is it necessary to generate a "custom.scss" file each time I start a fresh bootstrap project?

While following a Bootstrap tutorial by Kevin Powell, I encountered an issue where he copies a custom.scss file into a separate folder that I couldn't locate. This might be due to the fact that I'm using an updated version of Bootstrap. Accordin ...

Utilize an enum to serve as a blueprint for generating a fresh object?

I've defined an enum as shown below: export enum TableViewTypes { user = 'users', pitching = 'pitching', milestones = 'milestones', mediaList = 'mediaList', contacts = 'contacts' } ...

ngOnInit unable to properly listen to event stream

I've been trying to solve a persistent issue without success. The problem involves the interaction between three key elements: the HeaderComponent, TabChangingService, and TabsComponent. Within the HeaderComponent, there are three buttons, each with a ...

Compelling users to provide feedback on an App with the Ionic Framework

As a novice developer, I could use some assistance with implementing ratings in my app. My goal is to show menu items based on whether a user has given my app a 5-star rating. For instance, if a user gives a 5-star rating, I would assign the class "review ...

Display a dynamic array within an Angular2 view

I have a dynamic array that I need to display in the view of a component whenever items are added or removed from it. The array is displayed using the ngOnInit() method in my App Component (ts): import { Component, OnInit } from '@angular/core' ...

Steps to resolve npm ERR! Unexpected end of JSON input error when parsing near '...m":"b569e8103ed5b2ad3'

During my attempt at installing electron, I followed the command provided in the documentation: npm install electron --save-dev npm ERR! Unexpected end of JSON input while parsing near '...m":"b569e8103ed5b2ad3' npm ERR! A detailed ...

Issue: I am unable to locate the module '../../package.json' when attempting to run npm on the command line. Even running 'npm -v' results in an error message

Although I have come across similar questions, I am facing an issue with running anything using npm. Even a simple command like npm -v is throwing an error: C:\Users\Aloha>npm -v node:internal/modules/cjs/loader:1147 throw err; ^ Error: C ...

Issues with Laravel mix scripts not detecting any changes in the code

My current setup involves using webpack to watch for changes in my project's .js files. However, I need to use wildcards instead of specific file names. The commands I am using work well and compile all the expected files when I run npm run watch. The ...

Encountering an issue with installing node modules on a Mac M1 device, resulting in errors

Encountering an issue while trying to run npm i on my new Mac M1. Seeking assistance from the community to troubleshoot and provide a solution. Despite attempting multiple solutions, I keep encountering the same error message. npm WARN deprecated @hapi/&l ...

The count of bits is not producing the anticipated result

Attempting to tackle the challenge of Counting Bits using JavaScript, which involves determining the number of set bits for all numbers from 0 to N, storing them in an array, and returning the result Let me provide an explanation Input: n = 5 ...

What is the process for instructing npm to install custom library dependencies found within a specific library on npm central?

Currently, I am utilizing Angular 14 and have a special library project with the following folder structure: + projects + my-library - package.json Within the package.json file of this project, the contents are as follows: { "name" ...