webpack:字符串中的逗号导致捆绑期间语法错误

时间:2019-01-10 23:04:59

标签: javascript npm webpack bundle es6-modules

我正在尝试将此文件捆绑到我的主要js中。

var constants = {
    height: 600,
    width: 400,
    default_bezier = "[ { \"startPoint\" : [51.6503017608354,203.464445873753], \"endPoint\" : [-52.41285540263849,202.37245643258615], \"startControlPoint\": [-9.043960791649624,202.53176818590896], \"endControlPoint\" : [-57.822702172883595,218.9418611624324] }, { \"startPoint\" : [-52.41285540263849,202.37245643258615], \"endPoint\" : [-5.570997193470086,172.0221729966046], \"startControlPoint\": [-47.00300863239339,185.8030517027399], \"endControlPoint\" : [-23.03585320491517,179.86237947171952] }, { \"startPoint\" : [-5.570997193470086,172.0221729966046], \"endPoint\" : [9.324396434959688,9.376975066207507], \"startControlPoint\": [10.884005326634842,164.63530320382674], \"endControlPoint\" : [-4.968072864533834,110.62618662928577] }, { \"startPoint\" : [9.324396434959688,9.376975066207507], \"endPoint\" : [5.6297169670964,-110.17611809084356], \"startControlPoint\": [23.153152351097606,-88.58724679549941], \"endControlPoint\" : [-7.361202275296376,-53.760928830398264] }, { \"startPoint\" : [5.6297169670964,-110.17611809084356], \"endPoint\" : [53.717335525525975,-176.2424857013046], \"startControlPoint\": [14.357981611994795,-148.08003333114038], \"endControlPoint\" : [28.00328937556781,-176.2424857013046] } ]"
}

export {constants};

无论如何,它都会给此语法错误带来意外的标记,然后指向逗号:

ERROR in ./app/public/wp-content/themes/rise-child/js/maker-two/constants.js
Module build failed: SyntaxError: C:\Users\tinti\Local Sites\sextoys\app\public\wp-content\themes\rise-child\js\maker-two\constants.js:
expected token (5:16)

  3 |   height: 600,
  4 |   width: 400,
> 5 |   default_bezier = "[ { 'startPoint' : [51.6503017608354,203.464445873753], 'endPoint' : [-52.41285540263849,202.37245643258615], 'star
ntrolPoint': [-9.043960791649624,202.53176818590896], 'endControlPoint' : [-57.822702172883595,218.9418611624324] }, { 'startPoint' : [-52.41
540263849,202.37245643258615], 'endPoint' : [-5.570997193470086,172.0221729966046], 'startControlPoint': [-47.00300863239339,185.803051702739
 'endControlPoint' : [-23.03585320491517,179.86237947171952] }, { 'startPoint' : [-5.570997193470086,172.0221729966046], 'endPoint' : [9.3243
34959688,9.376975066207507], 'startControlPoint': [10.884005326634842,164.63530320382674], 'endControlPoint' : [-4.968072864533834,110.626186
28577] }, { 'startPoint' : [9.324396434959688,9.376975066207507], 'endPoint' : [5.6297169670964,-110.17611809084356], 'startControlPoint': [2
53152351097606,-88.58724679549941], 'endControlPoint' : [-7.361202275296376,-53.760928830398264] }, { 'startPoint' : [5.6297169670964,-110.17
809084356], 'endPoint' : [53.717335525525975,-176.2424857013046], 'startControlPoint': [14.357981611994795,-148.08003333114038], 'endControlP
t' : [28.00328937556781,-176.2424857013046] } ]"
    |                  ^
  6 | }

为什么我不能在字符串中使用逗号?

1 个答案:

答案 0 :(得分:3)

如此接近,但指针实际上指向该行的开头(尽管很难看到)。

default_bezier = "[ { \"startPoint\" : [51...
               ^

=应该是:,就像上面的两行一样。

尽管很难看到,但是您可以使用错误提供的信息进行检查,特别是

expected token (5:16)

其中5是行号(在本例中为带有default_bezier = ...的行),而16是列(字符)号。如果您从该行的开头算起17个字符(16 + 1,因为第一列是0),那么您将在=处结束:)