jasonaden / angular-cli-lib-example

Example of making an Angular CLI project with a library distributed separate from the app.
65 stars 14 forks source link

Angular compiler option "flatModuleIndex" requires one and only one .ts file in the "files" field #6

Closed vicatcu closed 6 years ago

vicatcu commented 6 years ago

Hi there! I'm having a bad time here trying to get npm run build:lib to succeed and I'm not sure what I'm doing wrong. Here's my console output:

Building Angular Package
Building entry point 'ng-mylib'
Rendering Stylesheets
Rendering Templates
Compiling TypeScript sources through ngc

BUILD ERROR
: Angular compiler option "flatModuleIndex" requires one and only one .ts file in the "files" field.

Error: : Angular compiler option "flatModuleIndex" requires one and only one .ts file in the "files" field.

    at Object.<anonymous> (/home/dev/ng-mylib/node_modules/ng-packagr/lib/ngc/compile-source-files.js:61:68)
    at Generator.next (<anonymous>)
    at /home/dev/ng-mylib/node_modules/ng-packagr/lib/ngc/compile-source-files.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/dev/ng-mylib/node_modules/ng-packagr/lib/ngc/compile-source-files.js:3:12)
    at Object.compileSourceFiles (/home/dev/ng-mylib/node_modules/ng-packagr/lib/ngc/compile-source-files.js:19:12)
    at Object.<anonymous> (/home/dev/ng-mylib/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:42:34)
    at Generator.next (<anonymous>)
    at /home/dev/ng-mylib/node_modules/ng-packagr/lib/ng-v5/entry-point/ts/compile-ngc.transform.js:7:71
    at new Promise (<anonymous>)

I've tried putting breakpoints down in the angular compile level, and what I'm seeing is the complaint happens because two rootFiles are being offered to createBundleIndexHost:

0:"/home/dev/ng-mylib/libs/ng-mylib/public_api.ts"
1:"/home/dev/ng-mylib/libs/ng-mylib/ng-mylib.ts"

I have not yet been able to figure out why that is the case though. Can you offer any pointers on where I might be going wrong? I think I followed the guidance on editing tsconfig.json and package.json files in the project, but clearly I missed something. Any help would be appreciated!

vicatcu commented 6 years ago

More diagnostics, I have a project that worked using "ng-packagr": "2.0.0-rc.13", and I tried just copying that project and updating to "ng-packagr": "^3.0.0-rc.2". That breaks it - which I guess shouldn't be a surprise considering the major version rolling - but it's not clear to me what changed about the configuration between 2 and 3. Any pointers?

vicatcu commented 6 years ago

I fixed it but frankly I'm not sure exactly what I did. I think I had carats in my package.json file associated with @angular packages and it maybe was non-compliant with the expectations of the angular_cli embedded in this project or something? Anyway, I'll close it.