简体   繁体   English

反应错误-./src/App.js第16行:解析错误:意外的令牌

[英]React error - ./src/App.js Line 16: Parsing error: Unexpected token

i tried a tutorial from their site and i encountered this error and i dont know what is wrong. 我从他们的站点尝试了一个教程,遇到了这个错误,我不知道出了什么问题。 This is the code: 这是代码:

function formatName(user) {
        return user.firstName + ' ' + user.lastName; //this is line 16
      }

      const user = {
        firstName: 'Ciofliceanu';
        lastName: 'Serban';
      };

      const element = <h1>Hello, {formatName(user)}</h1>;

      ReactDOM.render(element, document.getElementById('root'));

I expect the output to be Hello, Ciofliceanu Serban but the output is: ./src/App.js Line 16: Parsing error: Unexpected token 我期望输出为Hello,Ciofliceanu Serban,但输出为:./src/App.js第16行:解析错误:意外的令牌

The error is most likely really happening at definition of user as this is not a proper object literal: 该错误很可能确实发生在user定义上,因为这不是正确的对象文字:

const user = {
  firstName: 'Ciofliceanu';
  lastName: 'Serban';
};

Try replacing the ; 尝试更换; with , : ,

const user = {
  firstName: 'Ciofliceanu',
  lastName: 'Serban'
};

Hopefully that helps! 希望有帮助!

暂无
暂无

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

相关问题 ReactJS:语法错误:src / App.js:意外令牌(16:6) - ReactJS :Syntax error: src/App.js: Unexpected token (16:6) 我找不到错误,它显示为“Error in./src/App.js Syntax error: Unexpected token (11:5)” - I cannot find the error and it shows like this 'Error in ./src/App.js Syntax error: Unexpected token (11:5)' [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used 反应错误“ ./src/App.js第7行:&#39;APIKEY&#39;被分配了一个值,但从未使用过no-unused-vars” - React error “./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars” 在./src/App.js&#39;store&#39;中的反应错误未定义 - react Error in ./src/App.js 'store' is not defined Post 500 (Internal Server Error) line 48 app.js 和错误 SyntaxError: Unexpected token &lt; in JSON at position 0 line 65 in app.js - Post 500 (Internal Server Error) line 48 app.js and error SyntaxError: Unexpected token < in JSON at position 0 line 65 in app.js 解析错误:意外的令牌,应为“;” 在反应 JS - Parsing error: Unexpected token, expected “;” in react JS React js:./src/App.js第22行:未定义&#39;lastWinner&#39;no-undef搜索关键字以了解有关每个错误的更多信息 - React js: ./src/App.js Line 22: 'lastWinner' is not defined no-undef Search for the keywords to learn more about each error React Js:在 if else 语句中获取和错误行 50:20:解析错误:意外标记,预期“,” - React Js: Getting and error in if else statement Line 50:20: Parsing error: Unexpected token, expected "," 解析错误:基本 react.js 文件中 EOF 处的意外令牌“” - Parsing Error: Unexpected token "" at EOF in a basic react .js file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM