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

prerenderring - Angulartics2BaiduAnalytics ReferenceError: _hmt is not defined #476

Open
1 of 3 tasks
guoapeng opened this issue Nov 16, 2023 · 0 comments
Open
1 of 3 tasks

Comments

@guoapeng
Copy link

For support questions, please consider using Gitter - Chat

I am submitting an issue that when I running the following command to prerender some pages ng run demo-angular-project:prerender:development,
I got the following exception:

 Build at: 2023-11-16T08:00:28.460Z - Hash: b945708904bd624f - Time: 78602ms
⠙ Prerendering 13 route(s) to D:\dev\proj\demo-angular-project\dist\demo-angular-web\browser...ReferenceError: _hmt is not defined
    at new Angulartics2BaiduAnalytics (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199481:12)
    at Object.Angulartics2BaiduAnalytics_Factory [as factory] (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199536:10)
    at D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134269:33
    at runInInjectorProfilerContext (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:125777:5)
    at R3Injector.hydrate (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134268:9)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134148:23)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134157:27)
    at ChainedInjector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:138783:32)
    at lookupTokenUsingModuleInjector (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129505:31)
    at getOrCreateInjectable (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129551:10)
✖ Prerendering routes to D:\dev\proj\demo-angular-project\dist\demo-angular-web\browser failed.
_hmt is not defined
Unhandled Promise rejection: _hmt is not defined ; Zone: <root> ; Task: Promise.then ; Value: ReferenceError: _hmt is not defined
    at new Angulartics2BaiduAnalytics (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199481:12)
    at Object.Angulartics2BaiduAnalytics_Factory [as factory] (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199536:10)
    at D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134269:33
    at runInInjectorProfilerContext (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:125777:5)
    at R3Injector.hydrate (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134268:9)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134148:23)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134157:27)
    at ChainedInjector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:138783:32)
    at lookupTokenUsingModuleInjector (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129505:31)
    at getOrCreateInjectable (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129551:10) ReferenceError: _hmt is not defined
    at new Angulartics2BaiduAnalytics (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199481:12)
    at Object.Angulartics2BaiduAnalytics_Factory [as factory] (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:199536:10)
    at D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134269:33
    at runInInjectorProfilerContext (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:125777:5)
    at R3Injector.hydrate (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134268:9)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134148:23)
    at R3Injector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:134157:27)
    at ChainedInjector.get (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:138783:32)
    at lookupTokenUsingModuleInjector (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129505:31)
    at getOrCreateInjectable (D:\dev\proj\demo-angular-project\dist\demo-angular-web\server\main.js:129551:10)

I think when prerendering a page on server side, it's initializing _hmt. which is meaningful. should we skip that if we can detect it's in prerendering process to make the libarary more robust.

  • bug report

  • feature request

  • question about the decisions made in the repository

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

create an angular project and enableing angular universal and do preredering.

  • What is the expected behavior?

don't throw error if there is no _hmt found in ssr process.

  • What is the motivation / use case for changing the behavior?

to skip initialize Angulartics2BaiduAnalytics and do nothing during server side rendering.

  • Environment:

please run the following and copy the output

./node_modules/.bin/ng --version
Angular CLI: 16.2.10
Node: 16.14.2
Package Manager: npm 8.5.0
OS: win32 x64

Angular: 16.2.10
... animations, cli, common, compiler, core, elements, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.10
@angular-devkit/build-angular   16.2.10
@angular-devkit/core            16.2.10
@angular-devkit/schematics      16.2.10
@angular/cdk                    16.2.12
@angular/compiler-cli           16.2.12
@angular/language-service       16.2.12
@angular/material               16.2.12
@nguniversal/builders           16.2.0
@nguniversal/express-engine     16.2.0
@schematics/angular             16.2.10
rxjs                            7.4.0
typescript                      5.1.6
zone.js                         0.13.3
@guoapeng guoapeng changed the title Angulartics2BaiduAnalytics ReferenceError: _hmt is not defined prerenderring - Angulartics2BaiduAnalytics ReferenceError: _hmt is not defined Nov 16, 2023
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

1 participant