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

Document is not defined - Angular 17 #361

Open
BugProg opened this issue Nov 11, 2023 · 5 comments
Open

Document is not defined - Angular 17 #361

BugProg opened this issue Nov 11, 2023 · 5 comments

Comments

@BugProg
Copy link

BugProg commented Nov 11, 2023

Hi !

I just updated my project to Angular 17, and I'm using modern compilation method with Vite.
I have an issue with TypeIt, I get the following error: ERROR ReferenceError: document is not defined during the compilation.

    at select (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/typeit@8.7.1/node_modules/typeit/dist/index.es.js:207:1)
    at selectorToElement (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/typeit@8.7.1/node_modules/typeit/dist/index.es.js:237:32)
    at TypeIt (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/typeit@8.7.1/node_modules/typeit/dist/index.es.js:765:7)
    at _HomeComponent.ngAfterViewInit (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/src/app/user/home/home.component.ts:92:14)
    at callHookInternal (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:3437:5)
    at callHook (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:3461:3)
    at callHooks (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:3421:7)
    at executeInitAndCheckHooks (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:3375:1)
    at refreshView (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:13094:36)
    at detectChangesInView (/home/user/Projects/Angular/angular-project/.angular/vite-root/angular-project/node_modules/.pnpm/@angular+core@17.0.2_rxjs@7.8.1_zone.js@0.14.2/node_modules/@angular/core/fesm2022/core.mjs:13249:5)

NOTE
In spite of this error, the code seems to work perfectly in the browser.

@Rounaque-Noor
Copy link

It is happening due to SSR.
Use globalThis to fix.
I have done it for the error: ERROR ReferenceError: window is not defined.
For example: Use globalThis.window?.innerWidth instead of window.innerWidth.
I hope this helps.

@BugProg
Copy link
Author

BugProg commented Feb 27, 2024

Hi @Rounaque-Noor !

Thank you for your message ! I don't understand your fix.

This is my code, where I should insert your code ?

new (TypeIt as any)("#typeIt", {
  speed: 100,
  loop: true
})
  .type("Site-Web", {delay: 2000})
  .delete(() => {
  }, {delay: 1000, instant: false})
  .type("App  Mobile", {delay: 2000})
  .delete(() => {
  }, {delay: 1000})
  .type("Cloud", {delay: 2000})
  .delete(() => {
  }, {delay: 1000})
  .go();

Thank you.

@GeronimoSerial
Copy link

hi @BugProg !
you fix this? i have the exactly same issue with the same module

@BugProg
Copy link
Author

BugProg commented Mar 14, 2024

Hi @GeronimoSerial !
No, sorry, I didn't fix it yet.😢

@BugProg
Copy link
Author

BugProg commented Mar 20, 2024

Hi @GeronimoSerial,

The code below seems to work without errors:

import { isPlatformBrowser } from '@angular/common';

...

private isBrowser: boolean;

constructor(
 @Inject(PLATFORM_ID) platformId: Object) {
 this.isBrowser = isPlatformBrowser(platformId);
}

...

if (this.isBrowser) {
    new (TypeIt as any)("#typeIt", {
      speed: 100,
      loop: true
    })
      .type("CCC", {delay: 2000})
      .delete(() => {
      }, {delay: 1000, instant: false})
      .type("BBB", {delay: 2000})
      .delete(() => {
      }, {delay: 1000})
      .type("AAA", {delay: 2000})
      .delete(() => {
      }, {delay: 1000})
      .go();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants