Safari中带有Angular(V14)应用的空白页
“问题”
我有一个相当复杂的角度应用程序(目前V14),我有懒惰的模块,Angular I18n& MSAL-GANGULAR
集成。
同样,我的bootstrap在main.ts
中与“简单” Angular App不同。 例如引导程序:
fetch('/assets/settings.json')
.then(response => response.json())
.then(settings => {
googleTagManager();
platformBrowserDynamic([
{ provide: ENVIRONMENT, useValue: environment },
{ provide: SETTINGS, useValue: settings },
...
{
provide: MSAL_INSTANCE,
useFactory: MsalInstanceFactory,
deps: [REDIRECT_URI, LOCALE_URI_PREFIX, SETTINGS],
},
{
provide: MSAL_GUARD_CONFIG,
useFactory: MsalGuardConfigFactory,
},
{
provide: MSAL_INTERCEPTOR_CONFIG,
useFactory: MsalInterceptorConfigFactory,
deps: [SETTINGS],
},
])
.bootstrapModule(RootModule)
.catch((err) => console.error(err));
})
.catch(err => logger.error('Couldn\'t load \'/assets/settings.json\'', err));
在Chrome中,Firefox该应用程序按预期工作。
但是,当我以部署或本地服务模式将应用程序加载到Safari中时,我只有一个空白屏幕。那是因为在引导时,编译的JavaScript停止了很早。
我之后在DevTools中看到的是此例外:
ReferenceError: Can't find variable: _angular_forms__WEBPACK_IMPORTED_MODULE_2__
(anonymous function) — number-format.directive.ts:25
(anonymous function) — number-format.directive.ts:31
__webpack_require__ — bootstrap:19
...
现在您可能会说,只需解决该错误即可。显然,它在那里找不到东西...好吧...是的...首先,正如我所说,相同的代码在Chrome& Firefox(好的,好,有时这并不意味着什么)。 其次,当然,我尝试了整个事情,没有该例外中提到的代码。结果,例外消失了,但是页面仍然空白。因此,我再次查看DevTools,还有另一个不同的错误...一个类似的错误,又找不到东西。好的...修复了一个,然后再修复了其他事情……这不断地进行。
现在,关于这种行为最好,最丑陋的事情是: 当我使用并行打开的DevTool加载该应用程序时,该应用程序毫无问题 - 与Chrome& Firefox。
The "problem"
I have a pretty complex Angular app (currently v14), I have lazy modules, Angular i18n & msal-angular
integrated.
Also my bootstrap in main.ts
differs from a "simple" Angular app.
e.g. bootstrap:
fetch('/assets/settings.json')
.then(response => response.json())
.then(settings => {
googleTagManager();
platformBrowserDynamic([
{ provide: ENVIRONMENT, useValue: environment },
{ provide: SETTINGS, useValue: settings },
...
{
provide: MSAL_INSTANCE,
useFactory: MsalInstanceFactory,
deps: [REDIRECT_URI, LOCALE_URI_PREFIX, SETTINGS],
},
{
provide: MSAL_GUARD_CONFIG,
useFactory: MsalGuardConfigFactory,
},
{
provide: MSAL_INTERCEPTOR_CONFIG,
useFactory: MsalInterceptorConfigFactory,
deps: [SETTINGS],
},
])
.bootstrapModule(RootModule)
.catch((err) => console.error(err));
})
.catch(err => logger.error('Couldn\'t load \'/assets/settings.json\'', err));
In Chrome, Firefox the app works as expected.
But, when I load the app in Safari either in deployed or locally served mode I just have a blank screen. That is because while bootstrapping, the compiled JavaScript stops fairly early.
What I can see afterwards in DevTools, is e.g. this exception:
ReferenceError: Can't find variable: _angular_forms__WEBPACK_IMPORTED_MODULE_2__
(anonymous function) — number-format.directive.ts:25
(anonymous function) — number-format.directive.ts:31
__webpack_require__ — bootstrap:19
...
Now you might say, well, just fix that error. It obviously can't find something there... Well... yeah... First of all, as I said, the same code just runs fine in Chrome & Firefox (ok, fine, sometimes that doesn't mean anything).
Second, of course, I tried the whole thing without the code mentioned in that exception. As a result, the exception is gone, but the page is still blank. So, I check out DevTools again and there is another different error... A similar one, again it can't find something. Okay... fixed one, and then again, same thing with something else... this goes on and on and on.
Now, the best and most ugly thing about this behaviour is:
When I load the app with DevTools opened in parallel, the app works without any problems - just as expected the same way as in Chrome & Firefox. ???? No kidding!
Now you could say, okay, then there is something wrong with our OS, Mac, Safari, what ever... Well, yeah, maybe, I don't know. But, I have the same problem on different devices and other "clients"...
Wtf? Any idea?
I tried already really desperate things like replacing all display: grid
with display: flex
because I heard in some rare cases there is a problem with grid on Safari. I started to remove more and more code from the app but without success yet. (I'll continue on that, its my best chance…)
Btw. I found "similar" questions but no solutions (yet) here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是
tsconfig.json
...我从头开始重新创建了整个项目。一步一步地添加了我拥有的所有花哨的东西...在某个时候我也有同样的问题&我的最后一个更改是什么? ...
tsconfig.json
我有
esnext
(对于target
&module
)编译中的设置
)但,这打破了如所述的野生动物园(顺便说一句,也是iPad上的Firefox,Chrome)。我在es2020
上,这是目前我想的最佳实践。The solution was
tsconfig.json
...I recreated the whole project from scratch & added step by step all the fancy stuff I have... at some point I had the same problem & what was my last change? ... it was more or less in
tsconfig.json
I had
esnext
(for thetarget
&module
settings incompilerOptions
) BUT, this breaks Safari as described (btw. also Firefox, Chrome on iPad). I am ones2020
which is best practise currently I guess anyway.这是Safari版本的已知错误< 16。您可以阅读有关它的更多信息在这里。尽管您的用户可以升级到16或更高,以避免问题,但这可能并非总是一个选择。对于这些情况,您可以更新
.browserslistrc
文件以支持Safari的正确版本。在撰写本文时,这是我的文件看起来像是解决问题:This is a known bug for Safari versions < 16. You can read more about it here. While your users can upgrade to 16 or above to avoid the issue, that might not always be an option. For those cases, you can update your
.browserslistrc
file to support the correct version of Safari. At the time of writing this, here is what my file looked like to fix the problem: