简体   繁体   English

react-laravel 意外的令牌

[英]react-laravel Unexpected token

I am trying to get react-laravel working.我正在尝试让 react-laravel 工作。 I have installed everything correctly (v8js etc) but I keep getting:我已经正确安装了所有东西(v8js 等),但我不断收到:

V8Js::executeString():18903: SyntaxError: Unexpected token <

The problem seems to be with my component.js file:问题似乎出在我的 component.js 文件上:

var Application = React.createClass({
    render: function() {
        return (
            <div className="Networks">
                <ul>
                    <li>Test</li>
                </ul>
            </div>
        );
    }
});

How can I fix this?我该如何解决这个问题?


Also, is it possible to use ES6?另外,是否可以使用 ES6?


My view:我的观点:

<html>

<head>
    <title>JSPM Experiment</title>
    <script src="{{ asset('vendor/react-laravel/react.js') }}"></script>
    <script src="{{ asset('js/components.js') }}"></script>
    <script src="{{ asset('vendor/react-laravel/react_ujs.js') }}"></script>
</head>

<body>

<div id='react-root'>
</div>
@react_component('Application',[ 'title' => 'Hello, World' ], [ 'prerender' => true ])
</body>

</html>

Is it "component.js" or "components.js"?是“component.js”还是“components.js”? You likely have a typo.你可能有一个错字。

Usually you get SyntaxError: Unexpected token < when trying to load a javascript file that doesn't exist.通常,当您尝试加载不存在的 javascript 文件时,您会收到SyntaxError: Unexpected token < Laravel renders a 404 HTML page and the first < trips up your script tag. Laravel 会渲染一个 404 HTML 页面,第一个<触发你的脚本标签。

In case someone has still this error, I installed Laravel 6 and set up React:如果有人仍然出现此错误,我安装了 Laravel 6 并设置了 React:

php artisan preset react
npm install

And then I got a similar error "Syntax Error: Unexpected token" as the React JSX syntax didn't seem to be understood.然后我得到了一个类似的错误“语法错误:意外的标记”,因为 React JSX 语法似乎没有被理解。 It got fixed by altering babel config in webpack.mix.js :它通过更改webpack.mix.js babel 配置得到修复:

mix.babelConfig({
  "presets": [
    "@babel/preset-react",
  ],
});

If you have problem with Laravel 6. Please check your webpack.mix.js file, it should be mix.react() instead of mix.js()如果你对 Laravel 6 有问题,请检查你的webpack.mix.js文件,它应该是mix.react()而不是mix.js()

https://laravel.com/docs/6.x/mix#react https://laravel.com/docs/6.x/mix#react

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 来自中间件的react-laravel重定向问题 - react-laravel redirect issue from middleware React-Laravel(7.2)组件未显示在刀片中。php - React-Laravel(7.2) Component not showing in blade.php 如何在没有 php artisan serve 的情况下设置 React-Laravel 项目? - How to set up React-Laravel project with out php artisan serve? 未捕获的语法错误:Laravel/Vue 应用程序中出现意外的标记“&lt;” - Uncaught SyntaxError: Unexpected token '<' in Laravel/Vue Application Laravel 9 作曲家语法错误,意外标记“)” - Laravel 9 composer syntax error, unexpected token ")" Laravel Spatie 语法错误,意外标记“只读” - Laravel Spatie syntax error, unexpected token "readonly" Laravel 9 语法错误,意外令牌“返回” - Laravel 9 syntax error, unexpected token "return" Laravel Elixir Browserify失败!:意外的令牌 - 使用VueJs - Laravel Elixir Browserify Failed!: Unexpected token - Using VueJs 语法错误,在 Laravel 中调用“all()”或“get()”时出现意外标记“::” - syntax error, unexpected token "::" when calling "all()" or "get()" in Laravel 8 Laravel 返回 object 到 javascript 得到 Uncaught SyntaxError: Unexpected token '&amp;' 错误 - Laravel returning object to javascript getting Uncaught SyntaxError: Unexpected token '&' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM