ReactJS: “Uncaught SyntaxError: Unexpected token <”

前端 未结 9 1609
天命终不由人
天命终不由人 2020-11-27 02:45

I am trying to get started building a site in ReactJS. However, when I tried to put my JS in a separate file, I started getting this error: \"Uncaught SyntaxError: Unexpecte

相关标签:
9条回答
  • 2020-11-27 03:30

    JSTransform is deprecated , please use babel instead.

    <script type="text/babel" src="./lander.js"></script>
    
    0 讨论(0)
  • 2020-11-27 03:34

    If you are getting an error like this :

    SyntaxError: embedded: Unexpected token (107:9) 105

    It could be you are missing a curly bracket

    0 讨论(0)
  • 2020-11-27 03:34

    The code you have is correct. JSX code needs to be compiled to JS:

    http://facebook.github.io/react/jsx-compiler.html

    0 讨论(0)
  • 2020-11-27 03:38

    Add type="text/babel" to the script that includes the .jsx file and add this: <script src="https://npmcdn.com/babel-core@5.8.38/browser.min.js"></script>

    0 讨论(0)
  • 2020-11-27 03:42

    I have the same issue with you and I have change something in my server

    you might try this

    const root = require("path").join(__dirname, "./build");
    app.use(express.static(root));
    app.get("*", (req, res) => {
      res.sendFile("index.html", { root });
    });
    
    0 讨论(0)
  • 2020-11-27 03:44

    Try adding in webpack, it solved the similar issue in my project. Specially the "presets" part.

    module: {
        loaders: [
            {
                test: /\.jsx?/,
                include: APP_DIR,
                loader: 'babel',
                query  :{
                    presets:['react','es2015']
                }
            },
    
    0 讨论(0)
提交回复
热议问题