Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AssertionError [ERR_ASSERTION]: Compilation cannot be undefined after updating to Angular 15

Tags:

angular

Updated to Angular v15. When running ng test I am getting the following error:

⠋ Generating browser application bundles (phase: setup)...node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

AssertionError [ERR_ASSERTION]: Compilation cannot be undefined.
    at webpackOptions.entry (D:\wqems\WqEMS-portal\wqems-portal\node_modules\@angular-devkit\build-angular\src\webpack\plugins\styles-webpack-plugin.js:58:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

Node.js v18.12.1

Any help on what is going wrong would be highly appreciated.

like image 686
chadoulis Avatar asked May 12 '26 18:05

chadoulis


2 Answers

The error comes from the fact that a style file cannot be found during testing. In the angular.json file under "test.styles" the path to the *.(s)css must be adjusted so that they are valid.

e.g.:

"styles": ["src/styles/global.css"]

to

"styles": ["src/styles/global.scss"]

like image 155
Christopher W. Avatar answered May 14 '26 08:05

Christopher W.


I had this error, too, after upgrading Angular 14 -> 15, but only in one of my four subprojects. It turned out this single subproject did not have any karma tests (anymore), so the findTests() method of @angular-devkit did not find any matches to **/*.spec.ts and threw this misleading error.

In my case, I fixed it by simply adding a dummy test case, as I wanted to keep the working test chain for later.

like image 34
hoeni Avatar answered May 14 '26 08:05

hoeni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!