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

What is the best choice for a package.json file in an ASP.NET MVC project: devDependencies or dependencies?

I am currently in the process of developing an ASP.NET Core 2.0 MVC application and incorporating Angular 4 into it. To manage my dependencies, I have set up a configuration file named package.json in the root directory. Instead of using angular-cli, I ha ...

Learn how to manually trigger the opening of ngx-popover in Angular 2

I have implemented ngx-popover in my project. I am attempting to trigger it from a different component using a button click. Second Component HTML: <button popover #ChatPopover=popover (click)="ClickElement()"> <span class="glyphicon glyphico ...

Versions of Angular that are compatible with Ionic 2 (do not have an exported member)

How do I determine the compatible Angular version for each Ionic version? I keep encountering errors like "has no exported member." For example: The module ".../node_modules/@angular/core/index" does not have an exported member called InjectionToken. The ...

The FormControl is currently presenting ",required(control)" within its value field

Upon loading my form, the default values in the input fields are set to: ,required(control) { return isEmptyInputValue(control.value) ? { 'required': true } : null; } The template structure of my form is as follows: <form [formG ...

"Exploring the world of Typescript with the Drawflow library

Currently, I am integrating the fantastic Drawflow library created by @Jerosoler (available at: https://github.com/jerosoler/Drawflow) into my PrimeNg project. User @BobBDE has provided typescript definitions for this library here: https://www.npmjs.com/p ...

"Attempting to verify a JSON Web Token using a promise that returns an object not compatible with the specified

Learning about Typescript has been quite a challenge for me, especially when it comes to using the correct syntax. I have implemented a promise to retrieve decoded content from jwt.verify - jsonwebtoken. It is functioning as intended and providing an obje ...

The database is failing to reflect any changes even after using the db.insert function

I am currently working on implementing a forgot password feature in my express app using the node mailer package. This functionality involves sending a new password to the user's email and then updating the database with the new password. However, I h ...

Is there a way to transfer the opts/flags used in the npm install command to the postinstall scripts?

Is there a way to pass options and flags from the 'npm install' command to post-install scripts? For example, if I run npm install X --some-param=some-value, where package X has a post-install script located at ./scripts/postinstall.js, how can ...

Tips for reverting from Angular 7 to Angular 6

I attempted to switch from angular 7 back to angular 6 by executing the following npm commands: npm uninstall -g angular-cli npm cache clean npm install -g <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32535c55475e53401f515e5 ...

Should private members be kept confidential during program execution?

While Typescript's "private" members may not be truly private at runtime, traditional closures maintain the privacy of their members. Is there value in ensuring that private members remain private during runtime? ...

The installation of Angular CLI through npm has unfortunately encountered an error

After following the steps from this post to remove the old installation, I encountered an issue during the last step: [sudo] npm uninstall -g @angular/cli [sudo] npm cache verify [sudo] npm install -g @angular/cli During the final step, I faced difficult ...

Steps for running a TypeScript project as a child process within a JavaScript project

I am facing an issue with integrating my Electron app, written mainly in JavaScript, with an Express server project built in TypeScript. When I attempt to create a child process of the TypeScript project within my electron.js file, I encounter TypeScript e ...

Creating a customized environment variable for the global scope using Webpack build

Recently, I encountered a challenge with my Vue application which is compiled using Webpack. I wanted to include a variable in the 'npm run dev' command so that I could access it globally within the project. After running 'npm --brand=foo ru ...

Utilizing jspm for installing npm packages along with their dependencies

When using jspm, I can easily install npm packages by running: jspm install npm:<pkg-name>. This allows me to use the package in development, like so: import myPackage from 'myPackage';. If the package.json file of the npm package includes ...

An issue occurred during the installation of the generator-mean-seed

I'm currently attempting to follow the instructions outlined on https://www.npmjs.com/package/generator-mean-seed However, when I attempt to execute "sudo npm install -g generator-mean-seed," an error occurs: npm install -g generator-mean-seed npm W ...

Executing the jslint command on all files within a directory in cmd (specifically in the context of npm)

Click here If you're seeking information about running the jslint command on all JavaScript files within a directory and its subdirectories using the command prompt, check out the documentation provided at the linked URL. I have encountered an error ...

Error in Syntax for Raspberry Pi and Node-RED using npm

I am currently in the process of setting up a sensor node in Node-RED for my Raspberry Pi 3. The specific sensor I am using is the SDS011 air quality sensor, and the command required to install it is as follows: npm install node-red-contrib-sds011 Upon f ...

Validation errors in the realm of Zod

Below is my code using Next.js 14 with TypeScript, React Hook Form, and Zod for validation. The issue arises when trying to display an error message for an empty form: import React from "react"; import category from "@/components/expenses/ca ...

React-table fails to show newly updated data

I am facing an issue with my react-table where real-time notifications received from an event-source are not being reflected in the table after data refresh. https://i.stack.imgur.com/q4vLL.png The first screenshot shows the initial data retrieval from th ...

Difficulty with setting up Typescript in Visual Studio Code on MacOS Catalina

I'm currently facing an issue that appears to be related to the environment. How can I resolve it? And how do I link the installed TSC to my console? Steps to Recreate: npm install -g typescript was able to successfully install or update [email ...