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

Bug: "link.prev?.setAttribute is not a function" - CSP and <link rel="stylesheet"> #25575

Closed
1 task
majoer opened this issue Jul 24, 2023 · 2 comments
Closed
1 task
Labels
area: @angular-devkit/build-angular needs: investigation Requires some digging to determine if action is needed

Comments

@majoer
Copy link

majoer commented Jul 24, 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

No response

Description

ng build breaks when we combine ngCspNonce with a hard-coded style-sheet link in index.html.

We can replicate this in a new angular app. However, this problem first appeared for us in an Angular Universal app, with the following setup:

We believe this is where the bug occurs
https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/utils/index-file/inline-critical-css.ts#L149

Minimal Reproduction

How to reproduce:

  1. Run ng new
  2. Add ngCspNonce to index.html (nonce is hardcoded for testability)
  3. Add a stylesheet link to head: <link rel="stylesheet" href="..." />
  4. Run ng build, and see error

Repo with minimal reproduction: https://github.com/majoer/angular-csp-link-bug

Exception or Error

Index html generation failed.
link.prev?.setAttribute is not a function

Your Environment

Angular CLI: 16.1.5
Node: 16.17.0
Package Manager: npm 8.15.0
OS: linux x64

Angular: 16.1.6
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1601.5
@angular-devkit/build-angular   16.1.5
@angular-devkit/core            16.1.5
@angular-devkit/schematics      16.1.5
@angular/cli                    16.1.5
@schematics/angular             16.1.5
rxjs                            7.8.1
typescript                      5.1.6
zone.js                         0.13.1

Anything else relevant?

No response

@clydin clydin added needs: investigation Requires some digging to determine if action is needed area: @angular-devkit/build-angular labels Jul 24, 2023
@alan-agius4
Copy link
Collaborator

Duplicate of #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
Development

No branches or pull requests

3 participants