Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
PascalSwissDev opened this issue Jun 22, 2023 · 27 comments · Fixed by #25584
Closed
1 task done
Assignees
Labels
area: @angular-devkit/build-angular needs: investigation Requires some digging to determine if action is needed

Comments

@PascalSwissDev
Copy link

PascalSwissDev commented Jun 22, 2023

Command

build

Is this a regression?

  • 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

@klerick

This comment was marked as spam.

1 similar comment
@heikofritz

This comment was marked as spam.

@alan-agius4 alan-agius4 added needs: investigation Requires some digging to determine if action is needed area: @angular-devkit/build-angular labels Jun 22, 2023
@alan-agius4 alan-agius4 self-assigned this Jun 22, 2023
@alan-agius4 alan-agius4 added needs: repro steps We cannot reproduce the issue with the information given and removed needs: investigation Requires some digging to determine if action is needed needs: repro steps We cannot reproduce the issue with the information given labels Jun 23, 2023
@alan-agius4
Copy link
Collaborator

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 alan-agius4 added the needs: more info Reporter must clarify the issue label Jun 23, 2023
@PascalSwissDev
Copy link
Author

PascalSwissDev commented Jun 23, 2023

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.

@paulstelzer
Copy link

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.

@alan-agius4
Copy link
Collaborator

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 alan-agius4 added needs: repro steps We cannot reproduce the issue with the information given and removed needs: more info Reporter must clarify the issue labels Jun 23, 2023
@paulstelzer
Copy link

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.

@vlio20
Copy link

vlio20 commented Jun 23, 2023

@paulstelzer, is it a direct dependancy?

@paulstelzer
Copy link

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

@vlio20
Copy link

vlio20 commented Jun 23, 2023

Can you tell what dependancy?

@klerick
Copy link

klerick commented Jun 23, 2023

@vlio20
Copy link

vlio20 commented Jun 23, 2023

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

@alan-agius4
Copy link
Collaborator

critters already has a direct dependency on domhandler version 5.

https://unpkg.com/browse/critters@0.0.19/package.json

@Akxe
Copy link

Akxe commented Jun 23, 2023

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

@vlio20
Copy link

vlio20 commented Jun 23, 2023

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

@Akxe
Copy link

Akxe commented Jun 23, 2023

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.

@vlio20
Copy link

vlio20 commented Jun 23, 2023

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

@mazlano27
Copy link

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

@PascalSwissDev
Copy link
Author

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

@Akxe
Copy link

Akxe commented Jun 27, 2023

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

@JanST123
Copy link

Same issue here - the cause was also that domhandler 4.x was an additional dependency to domhandler 5.x. In my case this dependency was caused by @capacitor/* which I was using in version 4.x. Upgrading to 5.x fixed the problem

@niekhoogmanedap
Copy link

niekhoogmanedap commented Jul 2, 2023

Same problem here.

It seems to be gone when inlineCritical: false in angular.json.

 "optimization": {
    "styles": {
      "inlineCritical": false
    }
  }

Full path:
projects.app.architect.build.configurations.development.optimization.styles.inlineCritical

@blueiceprj
Copy link

Same problem here.

It seems to be gone when inlineCritical: false in angular.json.

 "optimization": {
    "styles": {
      "inlineCritical": false
    }
  }

Full path: projects.app.architect.build.configurations.development.optimization.styles.inlineCritical

This worked for me. Thanks.

@Moustingle
Copy link

I had the same problems, and changing the angular.json did not help in my case.

As mentionned earlier by several people, I manually installed domhandler with npm and everything went back to normal, with no modifications needed inside the angular.json.

@marksulls
Copy link

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

This worked for me. Thank you.

@alan-agius4 alan-agius4 added needs: investigation Requires some digging to determine if action is needed and removed needs: repro steps We cannot reproduce the issue with the information given labels Jul 26, 2023
@alan-agius4
Copy link
Collaborator

crisbeto added a commit to crisbeto/angular-cli that referenced this issue Jul 26, 2023
…g for external stylesheets

These changes revert the performance improvement from angular@e88aea6 and add a test. The problem with the previous approach is that it assumes that a `link` tag processed by Critters will be preceded by a `style` tag that was inserted by Critters. This assumption might not necessarily be true if Critters is unable to resolve the content of the linked styles. Furthermore, I'm not sure if we need to optimize this code path to begin with, because it only does a shallow traversal of the `head` tag which is generally fast and is unlikely to have many direct descendants.

Fixes angular#25419.
clydin pushed a commit that referenced this issue Jul 26, 2023
…g for external stylesheets

These changes revert the performance improvement from e88aea6 and add a test. The problem with the previous approach is that it assumes that a `link` tag processed by Critters will be preceded by a `style` tag that was inserted by Critters. This assumption might not necessarily be true if Critters is unable to resolve the content of the linked styles. Furthermore, I'm not sure if we need to optimize this code path to begin with, because it only does a shallow traversal of the `head` tag which is generally fast and is unlikely to have many direct descendants.

Fixes #25419.

(cherry picked from commit d6ae2c7)
clydin pushed a commit that referenced this issue Jul 26, 2023
…g for external stylesheets

These changes revert the performance improvement from e88aea6 and add a test. The problem with the previous approach is that it assumes that a `link` tag processed by Critters will be preceded by a `style` tag that was inserted by Critters. This assumption might not necessarily be true if Critters is unable to resolve the content of the linked styles. Furthermore, I'm not sure if we need to optimize this code path to begin with, because it only does a shallow traversal of the `head` tag which is generally fast and is unlikely to have many direct descendants.

Fixes #25419.
@angular-automatic-lock-bot
Copy link

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

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular needs: investigation Requires some digging to determine if action is needed
Projects
None yet