[ng6] `ng serve`; `ng build -prod` fails on `ng g library` dependent project
Versions
Angular CLI: 6.0.7
Node: 8.11.2
OS: darwin x64
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.7
@angular-devkit/build-angular 0.6.7
@angular-devkit/build-optimizer 0.6.7
@angular-devkit/core 0.6.7
@angular-devkit/schematics 0.6.7
@angular/cdk 6.2.0
@angular/cli 6.0.7
@angular/flex-layout 6.0.0-beta.15
@angular/material 6.2.0
@ngtools/webpack 6.0.7
@schematics/angular 0.6.7
@schematics/update 0.6.7
rxjs 6.2.0
typescript 2.7.2
webpack 4.8.3
Repro steps
ng new angular-vertical-tabs && cd $_ng add @angular/material; npm i --save @angular/flex-layout==6.0.0-beta.15ng g library material-tabs -p verticalng build material-tabs --prod- Add
distto git, then import in other Angular 6 project
https://github.com/SamuelMarks/angular-vertical-material-tabs
Observed behavior
Works fine on ng serve. On ng build --prod I get:
ERROR in ./node_modules/angular-vertical-tabs/dist/material-tabs/material-tabs.ngfactory.js
Module not found: Error: Can't resolve 'material-tabs' in 'my-new-repo/node_modules/angular-vertical-tabs/dist/material-tabs'
ERROR in ./src/app/slash/slash.module.ngfactory.js
Module not found: Error: Can't resolve 'material-tabs' in 'my-new-repo/src/app/slash'
ERROR in ./src/app/slash/slash.component.ngfactory.js
Module not found: Error: Can't resolve 'material-tabs' in 'my-new-repo/src/app/slash'
Desired behavior
ng build --prod should work.
Mention any other details that might be useful (optional)
My previous hack solution was to --aot false.
My error (and versions of everything) is nearly identical:
ERROR in ./node_modules/@nims/red-shared/lib/components/display-item-artifacts/display-item-artifacts.component.ngfactory.js
Module not found: Error: Can't resolve '../../../node_modules/@nims/ngutils/lib/editable-markdown/editable-markdown.component.ngfactory' in '/home/rtm/repos/nims/red/app/node_modules/@nims/red-shared/lib/components/display-item-artifacts'
@nims/red-shared is a library with a component called display-item-artifacts which is bringing in components such as editable-markdown from another library called ngutils. In case it matters, I'm compiling ngutils myself with ngc.
This was compiling fine before the upgrade to 6.0.0 etc., although I probably also changed some other things in the meantime. I also just realized that when I build/run the app in non-aot mode, the mentioned components (editable-markdown and some others for which I got the same error message and thus didn't show above) are not displayed--they're just missing.
Related? https://github.com/dherges/ng-packagr/issues/913, https://github.com/angular/material2/issues/11634
For me, it seems that removing the rootDir property of tsconfig.app.json solved the issue.
See this commit for more info: https://github.com/Chan4077/ngx-ytd-api/commit/5b1970cb090fc097e6bf748981d5c650958155ad
Dear all,
We fixed the issue on our side by making the following changes:
- removing "baseUrl": "./" from src/tsconfig.app.json file
- adding "paths" to tsconfig.json file
Hi,
I fixed the issue with the package.json name attribute in my lib. I wanted to use the library like this:
folder-structure:
| - node_modules
| - @mylib
| - components
| - etc
Import Statement in e.g. app.module.ts:
import { ExampleModule } from '@mylib/components';
The problem was that by generating ng g library mylib-components the package.json was named "name": "mylib-components" due to the library-structure
| - projects
| - mylib-components
| - src
Then it couldn't generate the mylib-component.ngfactory.js because it couldn't resolve the path as shown in the folder-structure @mylib/components. To solve the problem I changed the name in the package.json file to "name": "@mylib/components". And in the generated metadata.json file the "importAs: @mylib/components" is now correct instead of "importAs: mylib-components".
Now the production build works with the library.
Hope it helps.
Indeed it is paramount to set the name inside the package.json to the actual library name that will eventually be imported by the consumers, as this will be used as the flatModuleId for ngc.
Hi, We fixed the issue on our side by making the following changes:
- removing "paths": "./" from src/tsconfig.app.json file
- edit "paths" to tsconfig.json file
"baseUrl": "src/", "paths": { ... "agc": [ "../dist/agc" ], "agc/*": [ "../dist/agc/*" ] }
Got it working, Previously, I was uploading my repo-name/dist in my org/repo-name repository. Library was called lib0.
In org/repo-name2 angular project, I included in my package.json: {"repo-name": "org/repo-name"}. Compiled fine on ng build; ng build --prod proved the problem.
Pushing the dist directory to its own repository org/lib0; removing the previous from my package.json; then adding: {"lib0": "org/lib0"}; proved to be the solution.
Now ng build --prod works; and the rendered static files give no unexpected errors.
@olilutz that is the solution I ended on! Thanks for the help!
hi, import { Injectable } from '@angular/core'; import { Http, Response} from '@angular/http'; import 'rxjs/Rx';
@Injectable({ providedIn: 'root' }) export class ProfileService {
constructor( private http:Http) { }
saveprofile(){ let url="https://reqres.in/api/users"; return this.http.post(url, {name:'Meera', city:'kollam'}) .map((res:Response)=>res.json());
} }
I used the above code but it showing the error-Module not found: Error: Can't resolve 'rxjs/Rx/add/operator/map'. How can I solve it. The below versions I installed.
@ngtools/webpack 6.0.8 @schematics/angular 0.6.8 @schematics/update 0.6.8 rxjs 6.2.2 typescript 2.7.2 webpack 4.8.3
You need to import and use rxjs differently.
https://www.academind.com/learn/javascript/rxjs-6-what-changed/
On Mon, 23 Jul 2018 at 07:55, saranyatpillai [email protected] wrote:
import { Injectable } from '@angular/core'; import { Http, Response} from '@angular/http'; import 'rxjs/Rx';
@Injectable https://github.com/Injectable({ providedIn: 'root' }) export class ProfileService {
constructor( private http:Http) { }
saveprofile(){ let url="https://reqres.in/api/users"; return this.http.post(url, {name:'Saranya', city:'Adoor'}) .map((res:Response)=>res.json());
} }
I used the above code but it showing the error-Module not found: Error: Can't resolve 'rxjs/Rx/add/operator/map'. How can I solve it.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/11097#issuecomment-406947224, or mute the thread https://github.com/notifications/unsubscribe-auth/AQv-Wm6b_fD_nx5O8AFGPYqN2_-zw-h1ks5uJWVmgaJpZM4UYHDP .
Thank you.
@alan-agius4 Hi,
Still I'm facing this issue in one of my library. @ngu/carousel beta version. Don't know how to solve this issue
Git repo here
@sheikalthaf Could you tell me how did you solve that issue? I'm facing exactly same issue on my library https://www.npmjs.com/package/angular-ng-autocomplete . Here is my repo: https://github.com/gmerabishvili/angular-ng-autocomplete.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.