Skip to content

lmdb is not optional if using something that relies on @angular/build/private #32110

@fls95

Description

@fls95

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

20.3.13

Description

Some context before:

Through this refactoring:

5e29b44

The lmdb-cache-store.ts file is now being re-exported.

When transpiled (see https://www.npmjs.com/package/@angular/build/v/21.0.3?activeTab=code):

var lmdb_cache_store_1 = require("./tools/esbuild/lmdb-cache-store");

Now, lmbd-cache-store.ts imports lmdb (which later on will be require('lmdb')):

import { RootDatabase, open } from 'lmdb';

Where the problem starts:

Other files within this repository later on import stuff from @angular/build/private. Just as an example:

https://github.com/angular/angular-cli/blob/v21.0.3/packages/angular_devkit/build_angular/src/builders/server/index.ts#L9

Which ends up being transpiled as (https://www.npmjs.com/package/@angular-devkit/build-angular/v/21.0.3?activeTab=code):

const private_1 = require("@angular/build/private");

So, assuming a simple script such as:

const devkit = require("@angular-devkit/build-angular");

const executeServerBuilder = devkit.executeServerBuilder;

Will fail when run if lmdb is not installed (because of the chain of imports / requires).

Minimal Reproduction

Create a script such as the one mentioned above:

// index.js
const devkit = require("@angular-devkit/build-angular");

// Or anything that ends up loading `@angular/build/private`.
const executeServerBuilder = devkit.executeServerBuilder;
  1. Start a new npm package or similar: npm init -y
  2. Install @angular-devkit/build-angular, without installing the optional dependencies: npm i @angular-devkit/[email protected] --save-dev --omit optional.
  3. Run the previous script, e.g. node . or node index.js.

Exception or Error

node:internal/modules/cjs/loader:1386
  throw err;
  ^

Error: Cannot find module 'lmdb'

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI       : 21.0.3
Node.js           : 22.19.0
Package Manager   : npm 10.9.3
Operating System  : darwin arm64

┌───────────────────────────────┬───────────────────┬───────────────────┐
│ Package                       │ Installed Version │ Requested Version │
├───────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/build-angular │ 21.0.3            │ ^21.0.3           │
│ @angular/cli                  │ 21.0.3            │ ^21.0.3           │
└───────────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions