question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Published angular library AOT compilation issues

See original GitHub issue

Expected Behavior

When I build a lib using the ng build lib-name command and then do an npm publish (to a private nexus repository), then install this lib in a independent angular application, I should be able to import and use the Modules.

Current Behavior

When importing the Module from any of my nx published libraries I am getting an aot build error stating: ERROR in : Unexpected value 'MyModule in C:/**/**/**-components.d.ts' imported by the module 'AppModule in C:/**/**/src/app/app.module.ts'. Please add a @NgModule annotation

My IDE also flags the Module in the import Statement saying Class MyModule is not an Angular Module (I’m using intelliJ)

Failure Information (for bugs)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Create Nx repo
  2. Add a library MyLirary
  3. run ng build MyLibrary
  4. run npm publish dist/libs/MyLibrary --registry http://private-registry.com 5 do an npm install of @myWorkspace/MyLibrary
  5. Try to consume the library in app.module.ts ` import {MyModule} from ‘@myWorkspace/MyLibrary

@NgModule({ …, imports: [ MyModule ], … }) export class AppModule { }`

ALTERNATIVELY

  1. In your nx Workspace point the targets in your tsconfig.json file to the dist folder: "paths": { "@myWorkspace/MyLibrary": ["dist/libs//src/index.ts"] }
  2. In you nx Workspace in a app try to consume you library in the appModule similar to the above. AOT build should fail and IDE should complain.

Context

Please provide any relevant information about your setup:

  • version of Nx used: 8.2.0
  • version of Angular CLI used: 8.0.6
  • angular.json configuration: { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "", "projects": { "myWorkspace": { "projectType": "application", "schematics": { "@nrwl/workspace:component": { "style": "scss" } }, "root": "apps/myWorkspace", "sourceRoot": "apps/myWorkspace/src", "prefix": "dhs", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/apps/myWorkspace", "index": "apps/myWorkspace/src/index.html", "main": "apps/myWorkspace/src/main.ts", "polyfills": "apps/myWorkspace/src/polyfills.ts", "tsConfig": "apps/myWorkspace/tsconfig.app.json", "assets": [ "apps/myWorkspace/src/favicon.ico", "apps/myWorkspace/src/assets" ], "styles": ["apps/myWorkspace/src/styles.scss"], "scripts": [] }, "configurations": { "production": { "fileReplacements": [ { "replace": "apps/myWorkspace/src/environments/environment.ts", "with": "apps/myWorkspace/src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "aot": true, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "myWorkspace:build" }, "configurations": { "production": { "browserTarget": "myWorkspace:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "myWorkspace:build" } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "apps/myWorkspace/tsconfig.app.json", "apps/myWorkspace/tsconfig.spec.json" ], "exclude": ["**/node_modules/**"] } }, "test": { "builder": "@nrwl/jest:jest", "options": { "jestConfig": "apps/myWorkspace/jest.config.js", "tsConfig": "apps/myWorkspace/tsconfig.spec.json", "setupFile": "apps/myWorkspace/src/test-setup.ts" } } } }, "myWorkspace-e2e": { "root": "apps/myWorkspace-e2e", "sourceRoot": "apps/myWorkspace-e2e/src", "projectType": "application", "architect": { "e2e": { "builder": "@nrwl/cypress:cypress", "options": { "cypressConfig": "apps/myWorkspace-e2e/cypress.json", "tsConfig": "apps/myWorkspace-e2e/tsconfig.e2e.json", "devServerTarget": "myWorkspace:serve" }, "configurations": { "production": { "devServerTarget": "myWorkspace:serve:production" } } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": "apps/myWorkspace-e2e/tsconfig.e2e.json" } } } }, "MyLibrary": { "projectType": "library", "root": "libs/MyLibrary", "sourceRoot": "libs/MyLibrary/src", "prefix": "myWorkspace", "architect": { "build": { "builder": "@angular-devkit/build-ng-packagr:build", "options": { "tsConfig": "libs/MyLibrary/tsconfig.lib.json", "project": "libs/MyLibrary/ng-package.json" }, "styles": ["libs/MyLibrary/src/lib/themes.scss"] }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "libs/MyLibrary/tsconfig.lib.json", "libs/MyLibrary/tsconfig.spec.json" ], "exclude": ["**/node_modules/**", "!libs/MyLibrary/**"] } }, "test": { "builder": "@nrwl/jest:jest", "options": { "jestConfig": "libs/MyLibrary/jest.config.js", "tsConfig": "libs/MyLibrary/tsconfig.spec.json", "setupFile": "libs/MyLibrary/src/test-setup.ts" } } }, "schematics": { "@nrwl/angular:component": { "styleext": "scss" } } } }, "cli": { "warnings": { "typescriptMismatch": false, "versionMismatch": false }, "defaultCollection": "@nrwl/angular" }, "schematics": { "@nrwl/angular:application": { "unitTestRunner": "jest", "e2eTestRunner": "cypress" }, "@nrwl/angular:library": { "unitTestRunner": "jest" } }, "defaultProject": "myWorkspace" }
  • version of Angular DevKit used 0.801.0

Failure Logs

ERROR in : Unexpected value 'MyModule in C:/**/**/**-components.d.ts' imported by the module 'AppModule in C:/**/**/src/app/app.module.ts'. Please add a @NgModule annotation

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
vsavkincommented, Jul 9, 2019

@TaniaRall could you provide a repo with a repro?

0reactions
vsavkincommented, Feb 21, 2020

Sorry, the linked issue doesn’t seem to be relevant as it talks about npm linked libraries. Nx doesn’t use any linking because of the issues it causes. We also improved our support for buildable libraries, so a lot of issues related to that have been fixed.

I’m going to close this issue. If the problem is present when using Nx 8.12.7 or 9.0.2, please reopen it, and we will take a look asap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ahead-of-time (AOT) compilation - Angular
Compiles your application and libraries at build time. This is the default starting in Angular 9. When you run the ng build (build...
Read more >
AOT compilation fails when factory function imported from ...
AOT compilation fails when factory function imported from library is used in DI in Angular ; in ./src/app.component.ngfactory ; Module not found: ...
Read more >
Angular and AOT - CODE Magazine
Before any component can be rendered, its associated HTML template must be compiled. Not only that, but the application is bigger in size....
Read more >
Angular: Writing AoT-friendly applications | by David - Medium
Angular CLI comes with built-in AoT support. In the development target environment, it uses JiT (Just-in-Time) compilation for better developer experiences and ...
Read more >
Angular Ivy
AOT compilation with Ivy is faster and should be used by default. ... build. For more information on how to publish libraries see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found