Safari 中的默认 Angular-CLI 项目失败 - 罪魁祸首严格模式? [英] Default Angular-CLI Project Fails in Safari - culprit strict mode?

查看:23
本文介绍了Safari 中的默认 Angular-CLI 项目失败 - 罪魁祸首严格模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了最新版本的 angular-cli 并创建了一个全新的项目 (ng new my-app).这将创建始终时尚的欢迎使用应用程序",带有 Angular 徽标和指向英雄之旅、CLI 文档和 Angular 博客的链接.我可以使用 Chrome 和 Firefox 在我的 Windows 机器上提供它并在本地访问它.

I have installed the most-recent version of the angular-cli and created a brand new project (ng new my-app). This creates the always-stylish "Welcome to App" with the Angular logo and links to Tour of Heroes, the CLI Documentation, and the Angular blog. I can ng serve this and access it locally on my Windows machine using Chrome and Firefox.

当我尝试通过 Browserstack 访问相同的本地托管应用程序时,这会变得奇怪.当我从运行 Safari 11 的 Mac 上点击它时,一切都按预期工作.

Where this gets strange is when I try to access the same locally hosted app through Browserstack. When I hit it from a Mac running Safari 11, all works as expected.

但是,当我尝试通过运行 Safari 10+ 的 Mac 设备(例如 iPad)进行访问时,该应用程序将无法加载并收到错误消息:SyntaxError: Unexpected keyword 'const'.不支持 Const 声明在严格模式下".错误消息与我的 vendor.bundle.js 中的某个位置相关(在 eval 中).

However, when I try to access via a Mac device (iPad for example) running Safari 10+, the app will not load and I get the error message: "SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode". The error message is tied to a location in my vendor.bundle.js (in an eval).

根据我的阅读,当启用严格模式时,旧版本的 Safari 似乎不能很好地与常量配合使用.但是,我希望有一个解决方法.

From my reading, it appears that older versions of Safari don't play nice with consts when strict mode is enabled. But, I am hoping there is a work-around.

其他人如何处理这个问题?我不是 angular-cli 专家,所以如果有明显的解决方案,我很抱歉没有看到它.

How are others handling this? I am not an angular-cli expert, so if there is an obvious solution, my apologies for not seeing it.

如有任何帮助,我们将不胜感激.

Any assistance would be greatly appreciated.

推荐答案

我有同样的问题.webpack-dev-server(由@angular/cli 在后台使用)中似乎存在问题,它使用 ES6 功能并且没有被转译.

I have the same issue. It seems an issue in webpack-dev-server (used under the hood by @angular/cli) which uses ES6 features and is not being transpiled.

这只是旧版 Safari 的问题,但当您想在旧版 Safari 上进行测试时,更新 Safari 不是解决方案.

This is only a problem in older versions of Safari, but updating Safari is not a solution when you want to test on older Safari versions.

一个临时的解决方法是为 webpack-dev-server 使用旧版本,方法是安装它并手动将其复制到本地 @angular/cli 目录:

A temporary workaround is to use an older version for webpack-dev-server by installing it and copying it manually to the local @angular/cli directory:

yarn add webpack-dev-server@2.7.1 --dev
cp -R ./node_modules/webpack-dev-server ./node_modules/@angular/cli/node_modules/
./node_modules/.bin/ng serve

这篇关于Safari 中的默认 Angular-CLI 项目失败 - 罪魁祸首严格模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆