ng-packagr / ng-packagr

Compile and package Angular libraries in Angular Package Format (APF)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in fileLoaderPlugin for rollup while generating FESM after update to version 16

FelixKahmann opened this issue · comments

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

After updating to angular 16 (and ng-packagr 16) we ancounter a weird behaviour in our CI/CD-pipelines during FESM generation.
the ng build command for our libraries randomly exits with on of two errors
Error 1:

- Compiling with Angular sources in Ivy partial compilation mode.
✔ Compiling with Angular sources in Ivy partial compilation mode.
- Generating FESM bundles
✖ Generating FESM bundles
Could not load /home/administrator/myagent/_work/51/s/product/dist/our-namespace/our-package/esm2022/index.mjs (imported by dist/our-namespace/our-package/esm2022/our-namespace-our-package.mjs): Could not load '/home/administrator/myagent/_work/51/s/product/dist/our-namespace/our-package/esm2022/index.mjs' from memory.

Error 2:

- Compiling with Angular sources in Ivy full compilation mode.
✔ Compiling with Angular sources in Ivy full compilation mode.
- Generating FESM bundles
✖ Generating FESM bundles
Could not resolve entry module "dist/our-namespace/our-package/esm2022/our-namespace-our-package.mjs".

The package name that i replaced with 'our-package' in the error messages is not always the same.
After a bit of research i found out, that Error 1 is thrown in src/lib/flatten/file-loader-plugin.ts.
The is expected to be in the cache passed to the fileLoaderPlugin.

I am not sure whether the second error is ng-packagr related, but included it for completness.

Every now and then (roughly every 5th run), the pipeline completes successfully.

How To Reproduce

Unfortunatly we cannot even reproduce the error on our local dev machines (running windows 10 or ubuntu in WSL). The error only occures on our linux build agents (we are using azure dev ops with self-hosted agents).
Also our applicaton is propriatary and i am not able to share the source code.

Expected Behaviour

FESM generation completes always

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 16.1.0
@angular/compiler: 16.1.5
rollup: 3.26.3
typescript: 5.1.6
rxjs: 6.6.7
node: v18.14.2
npm/yarn: 9.5.0

Same issue here after upgrading to Angular 16.1, but it only happens locally for me (MacOS). On our CI it works as normal. So far I could not reproduce it in a clean Angular CLI project.

It seems related to some caching feature. When I set the CI environment variable (export CI=1), I no longer have the issue.

Deleting the .angular directory before the build also prevents the error from occuring (this is our current workaround which is a big performance hit for our pipelines).

Unfortunately without a reproduction it's hard to investigate this issue.

Hello @alan-agius4

steps to reproduce:

ng new reproduce --create-application false
ng g lib components
ng build components --configuration=development
ng build components --configuration=production

the problem starts from this commit: d3b9488

the outputCache in the cache is different and the hash is invalidated, here

the differences we saw here

when the build is done, I have these files:

angular-16/dist/components/esm2022/lib/components.module.js
angular-16/dist/components/lib/components.module.d.ts.map
angular-16/dist/components/lib/components.module.d.ts
angular-16/dist/components/esm2022/public-api.js
angular-16/dist/components/public-api.d.ts.map
angular-16/dist/components/public-api.d.ts
angular-16/dist/components/esm2022/components.js
angular-16/dist/components/components.d.ts.map
angular-16/dist/components/components.d.ts

and when build does not work, we have these files:

angular-16/dist/components/public-api.ngtypecheck.d.ts.map
angular-16/dist/components/public-api.ngtypecheck.d.ts
angular-16/dist/components/lib/components.module.ngtypecheck.d.ts.map
angular-16/dist/components/lib/components.module.ngtypecheck.d.ts
angular-16/dist/components/lib/components.module.d.ts.map
angular-16/dist/components/lib/components.module.d.ts
angular-16/dist/components/public-api.d.ts.map
angular-16/dist/components/public-api.d.ts
angular-16/dist/components/components.d.ts.map
angular-16/dist/components/components.d.ts
angular-16/.angular/cache/16.1.4/ng-packagr/tsbuildinfo/components.tsbuildinfo

and I'm not sure if I need to fix something here

const cache = sourcesFileCache.getOrCreate(source.fileName);

or you need to invalidate the cache here

cache: opts.cache ?? (cacheDirectory ? await readCacheEntry(cacheDirectory, opts.cacheKey) : undefined),

I'm not sure if I understood exactly how incremental typescript was implemented and at the moment I don't have enough time to investigate, but I hope I was useful.

Can you check if this is still reproducible with ng-packagr 16.2.3?

Thank you! With version 16.2.3 the error no longer occurs

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.