0

I am trying to get react-laravel working. I have installed everything correctly (v8js etc) but I keep getting:

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

The problem seems to be with my component.js file:

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?


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>
imperium2335
  • 23,402
  • 38
  • 111
  • 190

3 Answers3

0

Is it "component.js" or "components.js"? You likely have a typo.

Usually you get SyntaxError: Unexpected token < when trying to load a javascript file that doesn't exist. Laravel renders a 404 HTML page and the first < trips up your script tag.

Brad
  • 1,880
  • 1
  • 12
  • 18
0

In case someone has still this error, I installed Laravel 6 and set up 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. It got fixed by altering babel config in webpack.mix.js:

mix.babelConfig({
  "presets": [
    "@babel/preset-react",
  ],
});
Max Oriola
  • 1,296
  • 12
  • 8
0

If you have problem with Laravel 6. Please check your webpack.mix.js file, it should be mix.react() instead of mix.js()

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

Tan Nguyen
  • 1,636
  • 1
  • 12
  • 9