Published angular library AOT compilation issues
See original GitHub issueExpected 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.
- Create Nx repo
- Add a library
MyLirary
- run ng build MyLibrary
- run npm publish dist/libs/MyLibrary --registry http://private-registry.com 5 do an npm install of @myWorkspace/MyLibrary
- Try to consume the library in app.module.ts ` import {MyModule} from ‘@myWorkspace/MyLibrary’
@NgModule({ …, imports: [ MyModule ], … }) export class AppModule { }`
ALTERNATIVELY
- In your nx Workspace point the targets in your tsconfig.json file to the dist folder:
"paths": { "@myWorkspace/MyLibrary": ["dist/libs//src/index.ts"] }
- 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:
- Created 4 years ago
- Reactions:1
- Comments:7
@TaniaRall could you provide a repo with a repro?
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.