Angular2 beta 11 无法读取未定义的属性区域

标签 angular gulp browser-sync gulp-watch angular2-zone

我正在尝试在我的 gulp 管道上设置浏览器同步以进行开发,但我似乎无法重新加载。当我运行 gulp start 时会打开浏览器选项卡,但重新加载不会导致后续浏览器刷新。

我在 gulpfile 中遵循的步骤 -

gulp start - Build ts, copy js, libs and index.html. Start express server. Init browser-sync. Setup watch on source files.

此外,仅当我使用浏览器同步运行时才会出现此错误 图像 当我运行标准时,我没有看到上述错误 - gulp 节点 dist/app.js

我到处搜索,但找不到一个让我相信我的 gulp 工作流程有问题的例子。

还有一点可能会派上用场,那就是当我打开浏览器同步 UI 时 - Chrome dev tools - issued error

我可以确认<body>标签存在,这就是我的源代码在浏览器上的样子 -

<html>

<head>
    <base href="/">
    <title>Angular 2 QuickStart</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body><script type='text/javascript' id="__bs_script__">//<![CDATA[
    document.write("<script async src='/browser-sync/browser-sync-client.2.11.1.js'><\/script>".replace("HOST", location.hostname));
//]]></script>

<script src="lib/es6-shim.min.js"></script>
    <script src="lib/system-polyfills.js"></script>
    <script src="lib/shims_for_IE.js"></script>
    <script src="lib/angular2-polyfills.js"></script>
    <script src="lib/system.src.js"></script>
    <script src="lib/Rx.js"></script>
    <script src="lib/angular2.dev.js"></script>
    <script src="lib/router.dev.js"></script>
    <script src="lib/http.dev.js"></script>
    <script>
    System.config({
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
    System.import('app/main')
        .then(null, console.error.bind(console));
    </script>
    <my-app>Loading...</my-app>
</body>

</html>

我可以看到此处呈现的浏览器同步脚本标记。

我在这里完全不知所措。有人可以帮我解决这个问题/确定这是否是浏览器同步本身的问题吗?

这是我的 gulpfile -

var gulp = require('gulp');
var tsc = require('gulp-typescript');
var tsProject = tsc.createProject('client/tsconfig.json');
var sourcemaps = require('gulp-sourcemaps');
var config = require('./gulp.config')();
var del = require('del');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var node;
var spawn = require('child_process').spawn;
var path = require('path');

gulp.task('clean', function() {
    return del(config.distDir);
});

gulp.task('server', ['clean'], function() {
    return gulp.src(config.nodeHost)
        .pipe(gulp.dest(config.distDir))
});

gulp.task('lib', ['clean'], function() {
    return gulp.src(config.angularLibraries)
        .pipe(gulp.dest(path.join(config.distDir,'client','lib')));
});

gulp.task('compile-ts', ['clean'], function() {
    var sourceTsFiles = [
        config.allTs,
        config.typings
    ];

    var tsResult = gulp.src(sourceTsFiles)
        .pipe(sourcemaps.init())
        .pipe(tsc(tsProject));

    return tsResult.js
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(path.join(config.distDir,'client')));
});

gulp.task('index', ['compile-ts', 'lib', 'clean'], function() {
    return gulp.src(config.indexFile)
        .pipe(gulp.dest(path.join(config.distDir,'client')));
});

gulp.task('build', ['compile-ts', 'lib', 'index', 'server']);
gulp.task('default', ['build']);

// Deveopment serve tasks - start

gulp.task('watch', function() {
    gulp.watch(['./app.js', '!./dist/**', './client/**'], ['stop', 'reload']);
});

gulp.task('browser-sync', ['nodestart'], function() {
    browserSync.init(null, {
        proxy: "http://localhost:3001",
        port: 7000,
    });
});

gulp.task('reload-browser-sync', ['nodestart'], function() {
    reload();
});

gulp.task('nodestart', ['build'], function() {
    node = spawn('node', ['dist/app.js'], { stdio: 'inherit' })
    node.on('close', function(code) {
        if (code === 8) {
            gulp.log('Error detected, waiting for changes...');
        }
    });
});

gulp.task('start', ['build', 'nodestart', 'watch', 'browser-sync']);
gulp.task('reload', ['build', 'nodestart', 'reload-browser-sync']);
gulp.task('stop', function() {
    if (node) node.kill();
});

// Deveopment serve tasks - end

这是存储库 - https://github.com/saumyatripathi/angular_2_gulp_workflow

编辑:这是我在没有浏览器同步的情况下运行时的浏览器控制台。 No error on console

编辑:对于任何有兴趣跟踪我在浏览器同步存储库中提出的问题的进度的人,这里是链接 - https://github.com/BrowserSync/browser-sync/issues/1037

最佳答案

除了在 BrowserSync 存储库中创建的问题 OP 之外,还可以引用此 comment来自 Misko(引用)

The error is introduced by browser-sync-client.2.11.1.js trying to clearInteval(undefined)

这在pull request中得到了解决并将登陆 zone.js 0.6.5 和 beta.12(参见 #7700 )

更新

关于这个comment来自 BrowserSync 的作者@shakyShane,zone.js 0.6.5 可能并不能真正解决这个问题。请关注该问题和这些评论以获取更多信息。

更新2

根据 @stripathi 的反馈,此问题已在 beta.12 和 zone.js 0.6.6 中得到解决。

关于Angular2 beta 11 无法读取未定义的属性区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36121061/

相关文章:

javascript - 使用 Gulp 导入 ES6 模块

node.js - BrowserSync 非常慢

javascript - ServiceWorker 向 FetchEvent.respondWith() 传递了一个 promise ,该 promise 以非响应值 ‘undefined’ 解析。浏览器同步

javascript - Angular2 - 限制 p 内的行数

javascript - typescript如何在angular2中转换为javascript?

javascript - 在 Gulp 中,你如何否定多个项目,例如忽略一个文件和一个目录?

browser-sync - Lite Server 热重载不适用于默认配置

angular - 如何在 ngOnInit 中使用 await/async?

javascript - 具有异步数据的 Angular 2 动画

javascript - 正则表达式 - 查找具有特定字符串的所有评论