angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Error encountered when updating @angular-devkit/build-angular to Version 16.1.0

Open PascalSwissDev opened this issue 3 years ago • 27 comments

Command

build

Is this a regression?

  • [X] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

16.0.0

Description

Upon updating @angular-devkit/build-angular to Version 16.1.0, an error occurs during index HTML generation. The specific error message is "document.documentElement.setAttribute is not a function."

Upon investigation, I have identified the root cause of the issue. It appears that enabling the optimization option, specifically setting inlineCritical to True under styles, triggers the error. However, if this option is disabled, the build process completes successfully.

Minimal Reproduction

Command used: npx nx run project:build:production

Package use: @angular-devkit/build-angular 16.1.0

Exception or Error

√ Browser application bundle generation complete.
√ Copying assets complete.
× Index html generation failed.
document.documentElement.setAttribute is not a function
 ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
 >  NX   Ran target build for project *projectname* (58s)
 
    ×    1/1 failed
    √    0/1 succeeded [0 read from cache]

Your Environment

Angular CLI: 16.1.0
Node: 18.10.0
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 16.1.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.0
@angular-devkit/build-angular   16.1.0
@angular-devkit/core            16.1.0
@angular-devkit/schematics      16.1.0
@angular/cli                    16.1.0
@schematics/angular             16.1.0
rxjs                            7.8.1
typescript                      5.1.3

Anything else relevant?

No response

PascalSwissDev avatar Jun 22 '23 06:06 PascalSwissDev

+1

klerick avatar Jun 22 '23 10:06 klerick

+1

heikofritz avatar Jun 22 '23 11:06 heikofritz

I suspect that this is caused because the index.html does not have HTML tags.

Can you confirm that your index.html is a valid HTML document?

alan-agius4 avatar Jun 23 '23 08:06 alan-agius4

I can indeed verify that the index.html is valid. The only modification required is downgrading the version number to 16.0.0, after which it will function properly with the unchanged index.html.

PascalSwissDev avatar Jun 23 '23 10:06 PascalSwissDev

I can canfirm what @PascalSwissDev says. index.html is valid and if I reduce the index.html to only what it really needs the same error occurs. If i set inlinecritital to false or move back to 16.0.* everything is working again. But I have other projects with Angular 16.1 who are working without problems. So it seems to be a third-party-package that impacts the issue.

paulstelzer avatar Jun 23 '23 10:06 paulstelzer

Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

alan-agius4 avatar Jun 23 '23 13:06 alan-agius4

Could find it out. In my project where it is not working the npm package "domhandler" is installed with version 4.* and NOT 5.0

if I install "domhandler" with version 5 everything is working again. So a third party package installs an older version of domhandler while critters expects and needs version 5.

paulstelzer avatar Jun 23 '23 14:06 paulstelzer

@paulstelzer, is it a direct dependancy?

vlio20 avatar Jun 23 '23 14:06 vlio20

"domhandler" was installed by a third party package, now I am installed it directly in my "devDependencies"

paulstelzer avatar Jun 23 '23 15:06 paulstelzer

Can you tell what dependancy?

vlio20 avatar Jun 23 '23 15:06 vlio20

@vlio20 https://www.npmjs.com/package/critters

klerick avatar Jun 23 '23 16:06 klerick

So is it something that should be updated by the angular team?

vlio20 avatar Jun 23 '23 16:06 vlio20

critters already has a direct dependency on domhandler version 5.

https://unpkg.com/browse/[email protected]/package.json

alan-agius4 avatar Jun 23 '23 16:06 alan-agius4

In my case, I do have a build with "CommonJS or AMD dependencies". Maybe that is the source?

Akxe avatar Jun 23 '23 16:06 Akxe

In my case , I have validated that I am on a version of critters that is dependant on domhandler ^5.0.2

vlio20 avatar Jun 23 '23 18:06 vlio20

I would also like to point out that it does happen with webpack and esbuild but only in prod build.

And I do not use critters at all.

Akxe avatar Jun 23 '23 18:06 Akxe

@Akxe I can confirm this as well happens with webpack and esbuild

vlio20 avatar Jun 23 '23 18:06 vlio20

I was facing the same issue and deleting the node_modules folder & package-lock.json and reinstalling the dependencies fixed this issue for me

mazlano27 avatar Jun 25 '23 14:06 mazlano27

For me removing the package-lock.json also resolved the issue.

PascalSwissDev avatar Jun 27 '23 09:06 PascalSwissDev

It may be caused because of NPM vs YARN. I use NPM.

Use reactions to show what you use:

  • 👀 - NPM
  • 🚀 - YARN

Deleting the node_modules folder & package-lock.json and reinstalling did solve the issue too. I do really thing it might be an NPM issue when updating. I did update from 16.0.x => 16.1.x

Akxe avatar Jun 27 '23 10:06 Akxe