Angular 6 Library - Could not resolve entry

Abhishek picture Abhishek · Feb 27, 2019 · Viewed 7k times · Source

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?

Answer

Adrita Sharma picture Adrita Sharma · Mar 7, 2019

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