Is there a way to package a monorepo node project into a single file using ncc?

My tree structure is organized as follows:

├── package.json
├── tsconfig.json
└── packages
    ├── lib1
    │   ├── package.json
    │   ├── src
    │   │   ├── index.ts
    │   └── tsconfig.json
    ├── lib2
    │   ├── package.json
    │   ├── src
    │   │   ├── index.ts
    │   └── tsconfig.json
    ├── graph
    │   ├── package.json
    │   ├── src
    │   │   ├── index.ts
    │   └── tsconfig.json
    └── peer
        ├── package.json
        ├── src
        │   └── index.ts
        └── tsconfig.json

The dependency structure is that graph depends on lib2 which depends on lib1.

{
  "compilerOptions": {
    "target": "es2018",
    "module": "commonjs",
    "lib": ["es2018"],
    "moduleResolution": "node",
    "declaration": true,
    "strict": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "outDir": "build"
  },
  "exclude": ["**/node_modules", "**/build", "**/dist"]
}
{
  "extends": "../tsconfig-build.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "build"
  }
}

Everything works fine at compiletime, but when using @vercel/ncc for building, errors like

'rootDir' is expected to contain all source files.
occur.

    "build": "ncc build src/index.ts",

Trying out paths and references in my tsconfig.json did not solve the issue, and typescript does not seem to be resolving the different modules correctly. It works when pointing to the index.ts of peer, but it lacks workspace dependencies.

The ultimate goal is to ship a single js file to the docker container. How can I achieve this?

Answer №1

Our Monorepo is efficiently managed using Lerna.

https://github.com/lerna/lerna

Lerna provides the flexibility of handling both public and private packages. Public packages can be easily published to the registry, while dependencies within the same Monorepo need to be specified in the package.json file. Additionally, Lerna automates version incrementation for any changes made to dependent packages.

We have streamlined our auto-deployment process by utilizing GitHub actions with Lerna to publish public packages to the GitHub registry, increment all packages including private ones, and commit changes to the master branch.

Our configuration settings in lerna.json are:

{
  "version": "independent",
  "packages": ["packages/*"],
  "npmClient": "yarn",
  "ignoreChanges": ["**/*.md"],
  "useWorkspaces": true,
  "command": {
    "version": {
      "conventionalCommits": true,
      "createRelease": "github",
      "exact": true,
      "message": "chore(release): publish",
      "preid": "next"
    },
    "publish": {
      "distTag": "latest",
      "preDistTag": "next",
      "registry": "https://npm.pkg.github.com/"
    }
  }
}

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

How come ngOnChange is unable to detect changes in @Input elements when ngOnDetect is able to do so?

Check out this plunker Please note: In order to see the effect, you need to restart the app after entering the link. import {Component, OnInit, Input, OnChanges, DoCheck} from 'angular2/core' @Component({ selector: 'sub', templat ...

Encountered an error while deploying on Vercel: unable to connect to 54.178.252.149 on port 80

Here are the components in my environment: Environment Version Rails 7.0.0 Axios 0.26.1 React 18.0 Next.js 12.1.5 AWS EC2 Production Nginx Production I am attempting to deploy on Vercel for the first time. Currently, my Next.js app wo ...

The access to the HTTP response object is not possible: the property is not found on the Object type

I recently created a response object and assigned it to the "this" object. However, when I try to access the datacentersinfo property, I encounter an error stating that the property does not exist on type Object. Due to this issue, I am unable to generat ...

At compile time, Typescript runs smoothly, but errors may arise during runtime

Currently, I am delving into learning Typescript and have encountered a snag in my code. Despite searching extensively for a solution, I have been unable to find any relevant material pertaining to my issue. Below is the code snippet in question: <code ...

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 ...

What is the best way to reference class variables and methods within a callback function in Typescript?

While working on my Angular project with the Highcharts API, I encountered a situation where I needed to pass a state code to a class level method after drilling down to a specific map location. Below is the snippet of my current code: ngOnInit() { this. ...

Indicate the type of content returned by a Controller

I'm dealing with a metrics.controller.ts file that looks like this: import { Controller, Get } from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiUseTags, ApiModelProperty } from '@nestjs/swagger'; import { PrometheusSe ...

Mapping intricate entities to intricate DTOs using NestJS and TypeORM

Currently, I am using the class-transformer's plainToClass(entity, DTO) function to transform entities into DTO objects. In addition, I have implemented the transform.interceptor pattern as outlined in this source. I make use of @Expose() on propert ...

How to determine the presence of 'document' in Typecsript and NextJS

Incorporating NextJS means some server-side code rendering, which I can manage. However, I'm facing a challenge when trying to check for set cookies. I attempted: !!document && !!document.cookie as well as document !== undefined && ...

Converting docx files to PDF in Angular 15 using the "docxjs" library: A step-by-step guide

I am currently utilizing the to generate some docx files and enable downloading, but I am faced with the challenge of converting these files into PDF format. This is my current process: public download(data: any): void { const documentCreator = new D ...

Interacting with a form input by triggering the onChange event

I am encountering a problem where I need to be able to select a radio button both onChange via keydown and mouse click. However, I am struggling with accessing both event parameters of the on keydown and on mouse click within the same function. As a result ...

Can dynamic string types be declared in Typescript?

Let's consider the following scenario: export enum EEnv { devint, qa1 }; export type TEnv = keyof typeof EEnv; export const env:Record<TEnv, {something:number}> = { devint: { something: 1, }, qa1: { something: 1, }, } Now, I ai ...

Error: The function cannot be executed on an immutable object in React Native Jest unit testing with Typescript

Currently, I am experimenting with jest unit testing for a typescript-based react native project. However, I am facing an issue when I run npm test, and the error message is as follows: ● Test suite failed to run TypeError: seamless_immutable_1.default ...

Is there a way to insert data from one table into a MySQL Table in Drizzle and update the entry if it already exists?

My goal is to utilize Drizzle for inserting data into a table and updating it if the key already exists. In MySQL, the code would look like this: INSERT INTO myTable1(field1,field2,field3,field4) SELECT fieldOne,fieldTwo,fieldThree,fieldFour FROM myTable2 ...

Ensure thorough validation of the JSON.parsed data in TypeScript

Currently, I am developing a small module for Angular and I have encountered an issue regarding the condition where I verify my JSON.parsed data. read(): Position|null { try { ... let parsedData = JSON.parse(data); if (parsed ...

Bring in TypeScript property from an external scope into the current scope

I am encountering an issue with my TypeScript code. Inside the anonymous functions, I am unable to change the properties of the class because they are out of scope. Is there a way to pass them in so that they can be modified? class PositionCtrl { ...

Managing various situations using observables

Currently facing a coding dilemma: I have an observable that I need to subscribe to and certain requirements must be met: 1 - The registerUser function should only execute after processing the callback data. 2 - If registerTask returns data, I receive an ...

What is the solution for resolving this Angular issue: Expected argument expression.ts(1135)?

While following a CRUD tutorial, I encountered an issue with the code. Even though I have verified that my code matches the tutorial's code, I am getting an error message saying "Argument expression expected. ts(1335)" in the submit method onSubmit(). ...

What is the process for importing the Scale type definition from the Scale module?

Recently, I've been utilizing the Tonal package within a Vite/Vue/Typescript project. My current task involves importing the type known as Scale from the Scale module. You can find the type definition here: export interface Scale extends ScaleType { ...

What is the method to extract a single user instead of a group of users?

I am attempting to transition from a list of users to displaying the profile of a single user on a separate page. My goal is to achieve this using routerLink and passing the specific user's id to the next page. Although the routing is functioning co ...