7

I am getting the following error while building the angularlibrary project.

Building Angular Package
Building entry point '@abc/lib'
Compiling TypeScript sources through ngc
Bundling to FESM2015

BUILD ERROR
Could not resolve entry (C:\Dev\abc\build\dist-npm\esm2015\abc-lib.js)
Error: Could not resolve entry (C:\Dev\abc\build\dist-npm\esm2015\abc-lib.js)
    at error (C:\Dev\abc\node_modules\rollup\dist\rollup.js:3460:30)
    at C:\Dev\AppBuilder\node_modules\rollup\dist\rollup.js:21474:17

Could not resolve entry (C:\Dev\abc\build\dist-npm\esm2015\abc-lib.js)
Error: Could not resolve entry (C:\Dev\abc\build\dist-npm\esm2015\abc-lib.js)
    at error (C:\Dev\abc\node_modules\rollup\dist\rollup.js:3460:30)
    at C:\Dev\AppBuilder\node_modules\rollup\dist\rollup.js:21474:17

I only get this error when I add new module in public_api.ts file

export * from './lib/designer.service';
export * from './lib/designer.component';
export * from './lib/designer.module';
export * from './lib/core/app-core.module'; // new module

I am using the following command to build the module

ng build lib

Any idea why I am getting this error?

Abhishek
  • 621
  • 1
  • 8
  • 19
  • ???abc-lib.js??? I've never heard of such a thing... Q: Is this an Angular project you created yourself (e.g. with "ng new")? – paulsm4 Feb 27 '19 at 07:08
  • 1
    `abc-lib.js` is the library name. Specified in package.json. Example : `"name": "@abc/lib",` The angular library project was generated using `ng generate library lib` – Abhishek Feb 27 '19 at 07:47
  • The name "abc-lib.js" struck me as "suspicious". Q: Why not just delete it from package.json (along with any other place it's referenced in your project)? – paulsm4 Feb 27 '19 at 17:13
  • 1
    This is the name of my test library. Check build output `Building entry point '@abc/lib'` – Abhishek Mar 01 '19 at 00:49
  • Jeez! I didn't realize the entire problem was self-inflicted :( SUGGESTION: just create a new, darn "hello world" project (ng new hello), a new empty "hello world" library (ng g library hellolib), and do NOTHING ELSE besides edit one of your app's .ts files (e.g. app.component.ts) to "import" your library. SPELL THE LIBRARY NAME CORRECTLY! I'll betcha' it'll work fine. ALSO: try this: https://blog.angularindepth.com/creating-a-library-in-angular-6-87799552e7e5 – paulsm4 Mar 01 '19 at 04:22

2 Answers2

25

I was facing the same issue. My mistake was:

In one of my service in the library, I used environment variable and imported it like this:

import { environment } from 'src/environments/environment';

So while building, it couldn't get the relative path and was showing the error. I removed it and it worked fine.

Please ensure that in your library module, you are not referencing any main project related item or not importing any relative path

Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
  • 3
    similar issue for me: I had a lib that referenced another lib, but I had not built the shared lib yet, once I built the shared lib, the "parent" lib built fine. – lje Mar 16 '19 at 17:55
  • 1
    same issue for me: make sure your imports reference relative paths! thanks! – domenu May 21 '19 at 13:08
2

I had the same issue with my component library project. I was using library A into library B by referring that A library from the dist folder. The issue was because of referring library A by path.

I solved this issue by properly installing library A into B using npm install A@0.0.1.

This solved my problem.