SyntaxError:意外的令牌<在React.js中

时间:2015-06-12 14:26:16

标签: javascript reactjs react-jsx

从0.11.0升级到0.13.3后出现此错误。可能有什么不对? 我无法理解发生了什么,因为在一切正常之前就有一个评论jsx。

/**
 * @jsx React.DOM
 */
'use strict';
// config
var config = require('./config');
// dependencies
var React = require('react');
var ReactAsync = require('react-async');
// custom components
var Head = require('./modules/components/head');
// Main page component (this is asynchronous)
var NotFound = React.createFactory(
    React.createClass({
        displayName: 'NotFoundApp',
        mixins: [ReactAsync.Mixin],
        getInitialStateAsync: function (callback) {
            callback(null, this.props); // set the input props as state (equal to 'return this.props' in getInitialState, but async)
        },

        render: function() {
            return (
                <html>
                    //here is error
                </html>
            );
        }
    })
);
module.exports = NotFound;
if (typeof window !== 'undefined') {
    // enable the react developer tools when developing (loads another 450k into the DOM..)
    if (config.environment == 'development') {
        window.React = require('react');
    }
    window.onload = function () {
        React.renderComponent(NotFound(), document);
    }
}

这是浏览器的gulp任务:

var browserify = require('browserify');
var streamify = require('gulp-streamify');
var NopStream = require('../util/no-op-stream');
var uglify = require('gulp-uglify');
var gulp = require('gulp');
var handleErrors = require('../util/handle-errors');
var bundleLogger = require('../util/bundle-logger');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var gutil = require('gulp-util');

var production = process.env.NODE_ENV === 'production';

function createBundles(bundles, callback) {
    var bundleQueue = bundles.length;

    function reportFinished(bundleOptions) {
        bundleLogger.end(bundleOptions.output);

        if (bundleQueue) {
            bundleQueue--;
            if (bundleQueue === 0) {
                callback();
            }
        }
    }

    function createSingleBundle(bundler, bundleOptions) {
        bundleLogger.start(bundleOptions.output);

        bundler.bundle()
            .on('error', handleErrors)
            .pipe(source(bundleOptions.output))
            .pipe(production ? streamify(uglify()) : (new NopStream()))
            .pipe(gulp.dest(bundleOptions.destination))
            .on('end', function() {
                reportFinished(bundleOptions);
            });
    }

    bundles.forEach(function(bundleOptions) {
        var bundler = browserify({
            debug: !production,
            cache: {},
            packageCache: {},
            fullPaths: true,
            entries: bundleOptions.input,
            extensions: bundleOptions.extensions
        });

        if (global.isWatching) {
            bundler = watchify(bundler);

            // Rebundle on update
            bundler.on('update', function() {
                createSingleBundle(bundler, bundleOptions);
            });
        }

        createSingleBundle(bundler, bundleOptions);
    });
}

gulp.task('browserify', function(callback) {
    if(global.isWatching) {
        gutil.log('Watchify is enabled!');
    }

    createBundles([{
        input: ['./client/javascript/app.js'],
        output: 'app.js',
        destination: './client/public/javascript/'
    }, {
        input: ['./client/javascript/article.js'],
        output: 'article.js',
        destination: './client/public/javascript/'
    }, {
        input: ['./client/javascript/404.js'],
        output: '404.js',
        destination: './client/public/javascript/'
    }], callback);
});

1 个答案:

答案 0 :(得分:1)

尝试将 type =&#34; text / babel&#34; 添加到条目文件中的脚本文件

喜欢这个@micropost

相关问题