Angular 2,iOS Safari 错误:eval@[native code]

Posted

技术标签:

【中文标题】Angular 2,iOS Safari 错误:eval@[native code]【英文标题】:Angular 2, iOS safari Error: eval@[native code] 【发布时间】:2016-09-23 16:47:45 【问题描述】:

我有一个 node/express/angular 2 应用程序。在桌面 safari/chrome 中加载应用程序就可以了。没有错误。但是,如果我尝试将其启动到 ios Safari 移动浏览器中,我会收到:

Error: eval@[native code]
invoke@http://localhost:3001/js/vendor/zone.js/dist/zone.js:203:33
run@http://localhost:3001/js/vendor/zone.js/dist/zone.js:96:49
http://localhost:3001/js/vendor/zone.js/dist/zone.js:462:60
invokeTask@http://localhost:3001/js/vendor/zone.js/dist/zone.js:236:42
runTask@http://localhost:3001/js/vendor/zone.js/dist/zone.js:136:57
drainMicroTaskQueue@http://localhost:3001/js/vendor/zone.js/dist/zone.js:368:42
g@http://localhost:3001/js/vendor/es6-shim/es6-shim.min.js:11:1440
http://localhost:3001/js/vendor/es6-shim/es6-shim.min.js:11:1370
promiseReactionJob@[native code]
Evaluating http://localhost:3001/js/app/boot.js
Error loading http://localhost:3001/js/app/boot.js

不太确定这是否是一些加载问题?还是兼容性问题? index.hbs

<!doctype html>
<html lang="en">
<head>
<base href="/">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel='stylesheet' href='/stylesheets/style.css'/>
<link rel='stylesheet' href='/stylesheets/login-styles.css'/>
<link rel='stylesheet' href='/stylesheets/messenger-list-styles.css'/>

<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>

<script src="js/vendor/es6-shim/es6-shim.min.js"></script>
<script src="js/vendor/zone.js/dist/zone.js"></script>
<script src="js/vendor/reflect-metadata/Reflect.js"></script>
<script src="js/vendor/systemjs/dist/system.src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js"></script>

<script src="systemjs.config.js"></script>
</head>
<body>

<my-app>

</my-app>

<script>
    System.import('app').catch(function(err) console.error(err); );
</script>
</body>
</html>

包.json

 
  "name": "example",
  "version": "0.0.0",
  "private": true,
  "scripts": 
    "start": "node ./bin/www",
    "postinstall": "typings install",
    "typings": "typings",
    "vendor": "gulp vendor",
    "gulp": "gulp clean && gulp",
    "build:production": "gulp clean && gulp build && node systemjs.builder.js"
  ,
  "dependencies": 
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@angular/upgrade": "2.0.0",
    "angular2-in-memory-web-api": "0.0.20",
    "body-parser": "~1.13.2",
    "bootstrap": "^3.3.6",
    "cookie-parser": "~1.3.5",
    "core-js": "^2.4.1",
    "debug": "~2.2.0",
    "es6-shim": "^0.35.0",
    "express": "~4.13.1",
    "hbs": "~3.1.0",
    "jsonwebtoken": "^7.1.9",
    "mongoose": "^4.6.1",
    "morgan": "~1.6.1",
    "q": "^1.4.1",
    "reflect-metadata": "^0.1.3",
    "request": "^2.75.0",
    "rxjs": "5.0.0-beta.12",
    "serve-favicon": "~2.3.0",
    "systemjs": "0.19.27",
    "typings": "^0.8.1",
    "zone.js": "^0.6.23"
  ,
  "devDependencies": 
    "del": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-typescript": "^2.13.6",
    "systemjs-builder": "^0.15.19"
  

systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) 
    System.config(
        paths: 
            // paths serve as alias
            'npm:': 'js/vendor/'
        ,
        // map tells the System loader where to look for things
        map: 
            // our app is within the app folder
            app: 'js/app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            // other libraries
            'rxjs':                       'npm:rxjs',
            'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api',
        ,
        // packages tells the System loader how to load when no filename and/or no extension
        packages: 
            app: 
                main: './boot.js',
                defaultExtension: 'js'
            ,
            rxjs: 
                defaultExtension: 'js'
            ,
            'angular2-in-memory-web-api': 
                main: './index.js',
                defaultExtension: 'js'
            
        
    );
)(this);

【问题讨论】:

【参考方案1】:

您的 tsconfig.json 中是否有 es6 作为目标?如果将其更改为 es5,它应该可以工作。不幸的是,对 es6 的 Safari 支持非常糟糕。 我尝试使用 core-js shim,但也没有用。

如果你还想使用 Promise 之类的功能,你必须添加...

"files": [
  "../node_modules/typescript/lib/lib.es6.d.ts" 
],
"include": [
   "./*.*.ts" // where ever your typescript files are
]

...到你的 tsconfig 也是如此。这对我有用。

【讨论】:

以上是关于Angular 2,iOS Safari 错误:eval@[native code]的主要内容,如果未能解决你的问题,请参考以下文章

Angular.js 移动浏览器应用程序在 iOS 8 Safari 上冻结

Angular SPA PWA - Safari iOS 选项卡图标不会改变

iOS Safari(移动)和 Angular Material UI:专注于输入字段时不需要的闪烁文本

错误-TypeError:仅在向 Angular 5 应用程序内的 api 服务器发出 GET 请求后,在 Safari 上输入错误

错误 - TypeError:在对angular 5 app内的api服务器发出GET请求后,仅在Safari上键入错误

Web Share API 在 iOS 上不起作用:Angular