gpt4 book ai didi

javascript - 语法错误 : Unexpected token < in React. js

转载 作者:行者123 更新时间:2023-12-03 09:53:44 24 4
gpt4 key购买 nike

从 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);
}
}

这是 browserify 的 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);
});

最佳答案

尝试将 type="text/babel" 添加到入口文件中的脚本文件

像这样<script src="example.js" type="text/babel"></script>

关于javascript - 语法错误 : Unexpected token < in React. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30805484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com