Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Cannot read properties of undefined (reading 'setAttribute') #135

Closed
mgalasso opened this issue Aug 4, 2023 · 7 comments
Closed

Cannot read properties of undefined (reading 'setAttribute') #135

mgalasso opened this issue Aug 4, 2023 · 7 comments

Comments

@mgalasso
Copy link

mgalasso commented Aug 4, 2023

In Angular 16, during a build (ng build), there is an unhandled error within critters.js:519:30

Here is the code snippet within critters.js:
if (!crittersContainer) {
document.documentElement.setAttribute('data-critters-container', '');
crittersContainer = document.documentElement;
}

Here is the error message:
[error] TypeError: Cannot read properties of undefined (reading 'setAttribute')
at createDocument (C:\Development\sourcecode\sequoia\node_modules\critters\dist\critters.js:519:30)
at CrittersExtended.process (C:\Development\sourcecode\sequoia\node_modules\critters\dist\critters.js:1123:22)
at InlineCriticalCssProcessor.process (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\utils\index-file\inline-critical-css.js:167:40)
at C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\utils\index-file\index-html-generator.js:123:64
at IndexHtmlGenerator.process (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\utils\index-file\index-html-generator.js:65:34)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async execute (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\builders\browser-esbuild\index.js:107:47)
at async withSpinner (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\tools\esbuild\utils.js:73:16)
at async buildEsbuildBrowserInternal (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\build-angular\src\builders\browser-esbuild\index.js:207:18)
at async handleAsyncIterator (C:\Development\sourcecode\sequoia\node_modules@angular-devkit\architect\src\api.js:35:28)

As a consequence, the index.html cannot be built within the Angular project. (Index html generation failed.)

@scifresh
Copy link

scifresh commented Aug 24, 2023

i get a similar one with angular 16. and yes, only on ng build. the ng serve works perfect

✖ Index html generation failed. document.documentElement.setAttribute is not a function

@marco910
Copy link

I'm facing the same issue in Next.js 13 and [email protected]. It only happens with server-side rendering in some cases

@TheElegantCoding
Copy link

same here in vite

@saenif
Copy link

saenif commented Feb 14, 2024

same here. Angular 17. ng serve working perfectly. ng build failling with Index html generation failed. Cannot read properties of undefined (reading 'setAttribute') error

@briouyaasmae
Copy link

Same here with Angular 17

@KRS-envisageworld
Copy link

Also, facing the same issue while building the application. Does anyone know the root cause of this error?

@kara
Copy link
Collaborator

kara commented Oct 25, 2024

Closing this issue because ownership of Critters has moved to the Nuxt team, who will be maintaining the project going forward. This repo is archived and won't receive any future updates.

If the issue is still relevant, please re-post it to the actively-maintained fork at https://github.com/danielroe/beasties.

@kara kara closed this as completed Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants