简体   繁体   English

我有一个意外的令牌错误。 它来自哪里?

[英]I have an unexpected token error. Where is it coming from?

I'm being told there is an unexpected token error in my mapStateToProps function, but I'm failing to find it. 有人告诉我mapStateToProps函数中出现意外的令牌错误,但找不到。 Can you take a look and tell me what the problem is? 您能看一下并告诉我问题是什么吗?

import React from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'

const mapStateToProps = state =>({
  config: state.config,
  receipt: { receiptProducts = [] },
  expeditedShipping: state.expeditedShipping.expeditedProduct
})

@connect(mapStateToProps)

The error from my computer reads... 我计算机上的错误显示为...

ERROR in ./src/client/app/cbd-
mobile/components/receipt/ReceiptComponent.js
Module build failed: SyntaxError: Unexpected token, expected , (8:26)

   6 |   config: state.config,
   7 |   receipt: { receiptProducts = [] },
>  8 |   expeditedShipping: state.expeditedShipping.expeditedProduct
     |                           ^
   9 | })
  10 | 
  11 | @connect(mapStateToProps)

 @ ./src/client/app/index.jsx 31:24-83
 @ multi (webpack)-dev-server/client?http://localhost:8080 
./src/client/app/index.jsx
webpack: Failed to compile.

Thanks in advance. 提前致谢。

receipt: { receiptProducts: [] } instead of receipt: { receiptProducts = [] } receipt: { receiptProducts: [] }而非receipt: { receiptProducts = [] }

You would typically use { x = [] } when setting a default value for unpacking 设置拆包默认值时,通常会使用{ x = [] }

const { x = [] } = someVariable

in this case, though, you're just building a javascript object, so you only use : s 不过,在这种情况下,您只是在构建一个javascript对象,因此仅使用: s

意外的标记“<”,“<div id="text_translate"><p> 在过去的几天里,我一直在尝试解决这个错误。 我非常困惑,因为我不知道为什么这不起作用。 任何帮助或建议将不胜感激。</p><p> 当我尝试在我的客户端 js 中从 node.js 获取数据时,我的 JSON 解析器给我一个错误:</p><pre> uncaught SyntaxError: Unexpected token '<', "<.DOCTYPE "... is not valid JSON at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (something:js:18:29)</pre><p> 为此,我使用了 node、js 和 html,总共 3 个文件。 这是 index.js:</p><pre> const express = require('express'); const app = express(); app.use(express.static('public')); app.use(express.json()); app.listen(3000, () => { console.log('server started'); }); app.get('/', function(req, res) { console.log('hello') }); app.listen(8080); var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.post('/testing/thisshit', async function(req, res) { console.log(req.body); var dataToSendToClient = '{"message":"potatohead"}'; res.send(dataToSendToClient); });</pre><p> html:</p><pre> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div>hellow world</div> <script src="something.js"></script> </body> </html></pre><p> 客户端JS:</p><pre> console.log('testing') var abcd = {juice: "juice"} $.post( '/testing/thisshit', abcd); var res = new XMLHttpRequest(); var url = '/testing/thisshit'; res.open('GET',url,true); // set this to POST if you would like res.addEventListener('load',onLoad); res.addEventListener('error',onError); res.send(); function onLoad() { var response = this.responseText; console.log(response); var parsedResponse = JSON.parse(response); console.log("the result: " + parsedResponse) } function onError() { console.log('error'); }</pre><p> 无论我尝试什么,它似乎都让我感到困惑。 任何答案或建议都将非常有帮助,并提前感谢您提出任何建议。</p></div> - Unexpected token '<', "<!DOCTYPE "... is not valid JSON. Utilizing express and parsing error. Any suggestions would be great

暂无
暂无

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

相关问题 有错误:SyntaxError:意外的令牌,预期的“,” - 我试图返回一个数组,其中键名称:和时间戳:存在 - Have Error : SyntaxError: Unexpected token, expected “,” - I am trying to return an array where the keys name: and timestamp: are present “语法错误:意外的标记 &#39;:&#39;。解析错误。” JSON 和 ajax - "SyntaxError: Unexpected token ':'. Parse error." JSON & ajax 为什么会有“意外的令牌语法错误” - Why do I have an “Unexpected Token Syntax Error” 骨干错误来自何处? - Where is the Backbone error coming from? 我的意外令牌错误发生在哪里? - Where is my unexpected token error occurring? 语法错误:意外标记:&#39;{&#39; 问题出在哪里 - Syntax Error: unexpected token: '{' Where is the issue 这个未知错误来自何处以及如何防止它发生? - Where is this unknown error coming from and how to prevent it? 无法找到此中间件错误的来源 - Unable to find where this middleware error is coming from 意外的标记“<”,“<div id="text_translate"><p> 在过去的几天里,我一直在尝试解决这个错误。 我非常困惑,因为我不知道为什么这不起作用。 任何帮助或建议将不胜感激。</p><p> 当我尝试在我的客户端 js 中从 node.js 获取数据时,我的 JSON 解析器给我一个错误:</p><pre> uncaught SyntaxError: Unexpected token '<', "<.DOCTYPE "... is not valid JSON at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (something:js:18:29)</pre><p> 为此,我使用了 node、js 和 html,总共 3 个文件。 这是 index.js:</p><pre> const express = require('express'); const app = express(); app.use(express.static('public')); app.use(express.json()); app.listen(3000, () => { console.log('server started'); }); app.get('/', function(req, res) { console.log('hello') }); app.listen(8080); var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.post('/testing/thisshit', async function(req, res) { console.log(req.body); var dataToSendToClient = '{"message":"potatohead"}'; res.send(dataToSendToClient); });</pre><p> html:</p><pre> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div>hellow world</div> <script src="something.js"></script> </body> </html></pre><p> 客户端JS:</p><pre> console.log('testing') var abcd = {juice: "juice"} $.post( '/testing/thisshit', abcd); var res = new XMLHttpRequest(); var url = '/testing/thisshit'; res.open('GET',url,true); // set this to POST if you would like res.addEventListener('load',onLoad); res.addEventListener('error',onError); res.send(); function onLoad() { var response = this.responseText; console.log(response); var parsedResponse = JSON.parse(response); console.log("the result: " + parsedResponse) } function onError() { console.log('error'); }</pre><p> 无论我尝试什么,它似乎都让我感到困惑。 任何答案或建议都将非常有帮助,并提前感谢您提出任何建议。</p></div> - Unexpected token '<', "<!DOCTYPE "... is not valid JSON. Utilizing express and parsing error. Any suggestions would be great 我的 jsconfig.json 在反应 js 中出现错误,在 position 的 JSON 中说 throw err Unexpected token } - I have an error with my jsconfig.json in react js says throw err Unexpected token } in JSON at position
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM