Buildable libraries cannot import or export from non-buildable...

Discussão em 'Angular' iniciado por KRISH KAMANI, Março 31, 2025.

  1. KRISH KAMANI

    KRISH KAMANI Guest

    I am working with an Angular monorepo using Nx, and I've run into an issue while trying to build a component library that's set up to be publishable to npm. My project structure is as follows:

    nx-monorepo-root
    │
    ├── /apps
    │ ├── /app1
    │ └── /app2
    │
    ├── /libs
    │ ├── /shared-ui-lib
    │ ├── /app1Lib
    │ ├── /app2Lib
    │ ├── /prime-ng-lib
    │
    ├── /package
    │ └── /component-lib
    │
    ├── /tools
    │
    ├── /node_modules
    │
    ├── /dist
    │
    ├── nx.json
    ├── workspace.json
    ├── tsconfig.base.json


    I've created a buildable component library (component-lib) that I want to publish to npm. This library also depends on another library (prime-ng-lib) that wraps PrimeNG components.

    Here's the relevant code for component-lib:

    // Import statements
    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { Button1Component } from './button1/button1.component';
    import { PrimeNgLibModule } from '@monorepov2/prime-ng-lib'; // Importing the PrimeNG wrapper module

    @NgModule({
    imports: [CommonModule, PrimeNgLibModule],
    declarations: [Button1Component],
    exports: [Button1Component]
    })
    export class G99UiLibModule {}


    But when I try to import primeNgLibrary module in component lib I am getting below error which is fixed if I add eslint disable rule Buildable libraries cannot import or export from non-buildable libraries eslint@nx/enforce-module-boundaries

    When I try to build component-lib, I encounter the following error:


    PS C:\Users\Desktop\Workspace\Learning\Angular\g99\monorepov2> npx nx build g99-ui-lib

    > nx run g99-ui-lib:build:production

    Building Angular Package

    ------------------------------------------------------------------------------
    Building entry point 'g99-ui-lib'
    ------------------------------------------------------------------------------
    - Compiling with Angular sources in Ivy partial compilation mode.
    ✖ Compiling with Angular sources in Ivy partial compilation mode.
    NX Cannot destructure property 'pos' of 'file.referencedFiles[index]' as it is undefined.
    Pass --verbose to see the stacktrace.


    Additionally, when I remove the dependency on prime-ng-lib, the build process works fine. The code also works as expected when running locally.

    Questions:


    • How can I resolve the issue of building a buildable library (component-lib) that depends on a non-buildable library (prime-ng-lib) in an Nx workspace?


    • Are there any recommended solutions or best practices for handling dependencies between buildable and non-buildable libraries in Nx?

    **Additional Information:

    I've tried using the --verbose flag but didn't find much detail in the stack trace. My Nx and Angular versions are up-to-date.

    Continue reading...

Compartilhe esta Página