Skip to content

bug: Angular compilation initialization failed thrown when using "styles: \...\" #49

@michael-small

Description

@michael-small

Background

(links to repro at end)

Angular projects can define styles directly inside the @Component decorator like so: https://angular.dev/guide/components/styling

@Component({
  ...
  styles: ` img { border-radius: 50%; } `,
})
export class ProfilePhoto { }

However...

The Bug

The following error is thrown when serving an Angular app with the latest starter with such styles declaration (that are not empty)

~/projects/stackblitz-starters-8q9thuwb
❯ npm install && npm start

added 462 packages in 3s

81 packages are looking for funding
  run `npm fund` for details

> start
> ng serve

Prebundling has been configured but will not be used because caching has been disabled.
Prebundling has been configured but will not be used because caching has been disabled.
Application bundle generation failed. [2.989 seconds]

✘ [ERROR] Angular compilation initialization failed. [plugin angular-compiler]

  Error: Digest method not supported
      at new _0x1871ea (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/blitz.c8c182a3.js:40:835644)
      at new Hash (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:70:945)
      at createHash (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:24:2531)
      at Object.transformStylesheet (file:///home/projects/stackblitz-starters-8q9thuwb/node_modules/@angular/build/src/tools/esbuild/angular/compiler-plugin.js#cjs:160:64)
      at _0x663055.eval (file:///home/projects/stackblitz-starters-8q9thuwb/node_modules/@angular/build/src/tools/angular/compilation/parallel-compilation.js#cjs:42:18)
      at [nodejs.internal.kHybridDispatch] (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:102:8637)
      at t.emitMessage (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:169:364)
      at https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/blitz.c8c182a3.js:40:879998
      at https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/blitz.c8c182a3.js:40:199058
      at _0x2d0d9d (https://stackblitzstarters8q9thuwb-22r5.w-credentialless-staticblitz.com/blitz.c8c182a3.js:40:199172)


Watch mode enabled. Watching for file changes...

That said, when I download the project and run it locally (link to repo in the last section), it works as intended.

Other notes

  • This isn't an issue when it is just an empty "styles: ``"
  • I have not had issues with these in-component styles in Stackblitz until this issue in the last day or two
    • I don't have good examples of working ones since I always fork my own starter with a lot more dependencies, but here is one with the same type of styles that just works: https://stackblitz.com/edit/bfjmf2-k1gcxd?file=src%2Fmain.ts. However, I think I have had this upgraded since v18 so it probably is configured different out of the box before I made major changes anyways.
  • edit: system info
    • Windows 11
    • Happens on the latest versions of my 3 browsers
      • Chrome (Version 131.0.6778.205 (Official Build) (64-bit))
      • Firefox (133.0.3 (64-bit))
      • Edge (Version 131.0.2903.112 (Official build) (64-bit))

Links to Reproductions

Broken Stackblitz project: https://stackblitz.com/edit/stackblitz-starters-8q9thuwb?file=src%2Fmain.ts

Downloaded project repo, which can be ran with npm install && npm start: https://github.com/michael-small/stackblitz-angular-styles-error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions