TypeError,开发环境中未定义的“摘要" [英] TypeError, 'digest' of undefined, in development environment
问题描述
当我们为本地主机构建Angular SPA时,它运行完美.
When we're building our Angular SPA for localhost it works perfectly.
在我们的开发环境中,此错误会渗入DevTool控制台并破坏所有内容: 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性摘要"
On our dev environment, this error creeps into the DevTool console and breaks everything: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'digest' of undefined
TypeError: Cannot read property 'digest' of undefined
at N (auth0-spa-js.production.js:1)
at ie.<anonymous> (auth0-spa-js.production.js:1)
at Generator.next (<anonymous>)
at auth0-spa-js.production.js:1
at new ZoneAwarePromise (zone-evergreen.js:876)
at t (auth0-spa-js.production.js:1)
at ie.loginWithRedirect (auth0-spa-js.production.js:1)
at AuthGuard.<anonymous> (auth.guard.ts:22)
at Generator.next (<anonymous>)
at fulfilled (environment.ts:11)
at resolvePromise (zone-evergreen.js:797)
at new ZoneAwarePromise (zone-evergreen.js:879)
at t (auth0-spa-js.production.js:1)
at ie.loginWithRedirect (auth0-spa-js.production.js:1)
at AuthGuard.<anonymous> (auth.guard.ts:22)
at Generator.next (<anonymous>)
at fulfilled (environment.ts:11)
at ZoneDelegate.invoke (zone-evergreen.js:359)
at Object.onInvoke (core.js:34195)
at ZoneDelegate.invoke (zone-evergreen.js:358)
我想这一定是关于构建过程的东西,有一些不同的标志,但是我无法确切地找出哪个.
I guess it must be something about the build process, some different flags, but I can't figure out exactly which.
推荐答案
可能是因为您的开发服务器设置为不安全的来源.
It's probably because your dev server is setup as an insecure origin.
digest
可能引用网络加密的window.crypto.subtle.digest
API .如果您使用的是基于Chromium的浏览器,请根据此处的Chromium项目页面,subtle
属性只能在安全来源中使用:
The digest
likely refers to window.crypto.subtle.digest
of the Web Crypto API. if you are using a Chromium-based browser, according to the the Chromium Projects page here, the subtle
property can only be used in a secure origin:
对WebCrypto API的访问仅限于安全来源(即https://页面).
Access to the WebCrypto API is restricted to secure origins (which is to say https:// pages).
注意:在规范中,crypto.subtle应该在不安全的上下文中未定义
Note: In the spec, crypto.subtle is supposed to be undefined in insecure contexts
由于digest
是subtle
的方法,而subtle
是undefined
,因此出现此错误.
Because digest
is a method of subtle
, and subtle
is undefined
, you are getting this error.
使用 auth0-spa-js库时,我们遇到了相同的错误.它可以在localhost上运行,而不是在我们的http临时站点上运行,但在我们的生产https站点上可以.
We got the same error when using the auth0-spa-js library. It worked on localhost, not on our http staging site, but OK on our production https site.
如果您不是一个安全来源,请尝试使您的开发环境安全,然后再次进行测试(应该执行自签名证书).提醒一下,安全来源是:
If you aren't in a secure origin, try making your dev environment secure and then testing again (a self-signed certificate should do). As a reminder, secure origins are:
哪个起源是安全的"?
安全来源是指至少与以下(方案,主机,端口)模式之一匹配的来源:
Which origins are "secure"?
Secure origins are those that match at least one of the following (scheme, host, port) patterns:
- (https,*,*)
- (wss,*,*)
- (*,localhost,*)
- (*,127/8,*)
- (*,:: 1/128,*)
- (文件,*,—)
- (chrome-extension,*,—)
- (https, *, *)
- (wss, *, *)
- (*, localhost, *)
- (*, 127/8, *)
- (*, ::1/128, *)
- (file, *, —)
- (chrome-extension, *, —)
也就是说,安全来源是指从本地计算机(必要时受信任)或通过网络从加密身份验证的服务器加载资源的来源.
That is, secure origins are those that load resources either from the local machine (necessarily trusted) or over the network from a cryptographically-authenticated server.
我不确定 Auth0 小组是否有可在非安全来源(或计划)中使用的SPA库.以在其最新的SPA库中启用该功能),但其本地JS库肯定可以.
I'm not sure if the Auth0 team have an SPA library that works in a non-secure origin (or plans to enable that capability in their latest SPA library), but their native JS libraries definitely do.
这篇关于TypeError,开发环境中未定义的“摘要"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!