标签: unexpected-token

SyntaxError:意外的标识符jest和babel 7和react-native 0.56

将React本机版本升级到0.56后,我无法运行测试。升级之前,我正在测试我的应用程序。

我收到SyntaxError:意外的标识符错误。

详情如下。你能帮我吗?

这是我的devDependencies。

"@babel/core": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"babel-preset-react-native": "^5.0.2",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.4",
"jest": "^23.4.2",
"react-addons-test-utils": "^15.6.2",
"react-dom": "^16.4.2",
"react-test-renderer": "^16.4.2",
"regenerator-runtime": "^0.12.1",
"sinon": "^6.1.5"
Run Code Online (Sandbox Code Playgroud)

我以这种方式配置了玩笑。

"jest": {
  "preset": "react-native",
  "snapshotSerializers": [
    "enzyme-to-json/serializer"
  ],
  "setupTestFrameworkScriptFile": "<rootDir>/setupTest.js"
} 
Run Code Online (Sandbox Code Playgroud)

.babelrc

{
  "presets": ["react-native"],
  "plugins": [
    "@babel/plugin-proposal-optional-chaining"
  ]
}
Run Code Online (Sandbox Code Playgroud)

错误详情-1

import KeyboardAwareMixin from './lib/KeyboardAwareMixin';
       ^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier

  1 | import React from "react";
  2 | import {View} from "react-native";
> 3 | import …
Run Code Online (Sandbox Code Playgroud)

testing jestjs babeljs react-native unexpected-token

11
推荐指数
1
解决办法
3125
查看次数

如何修复第三方依赖项中的 Vite 构建/解析器错误“Unexpected token”?

我正在尝试使用 Vite 创建 React 应用程序的生产版本。当我运行该npm run dev命令时,应用程序将启动并且似乎可以正常工作,但在构建过程中,我总是会因某些第三方依赖项而收到此类解析器错误,表明它包含意外的令牌。

\n

我的配置文件中是否缺少某些内容或者可能是什么?

\n
\xe2\x9d\xaf npm run build\n\n> project build\n> tsc && vite build\n\nvite v2.9.12 building for production...\n\xe2\x9c\x93 4 modules transformed.\n[commonjs] Unexpected token (1:20) in /Users/../node_modules/react-router-dom/index.js\nfile: /Users/../node_modules/react-router-dom/index.js:1:20\n1: /**\n      ^\n2:  * React Router DOM v6.3.0\n3:  *\nerror during build:\nSyntaxError: Unexpected token (1:20) in /Users/../node_modules/react-router-dom/index.js\n    at Parser.pp$4.raise (/Users/../node_modules/rollup/dist/shared/rollup.js:19740:13)\n    at Parser.pp$9.unexpected (/Users/../node_modules/rollup/dist/shared/rollup.js:17034:8)\n    at Parser.pp$5.parseIdent (/Users/../node_modules/rollup/dist/shared/rollup.js:19671:10)\n    at Parser.pp$8.parseImportSpecifiers (/Users/../node_modules/rollup/dist/shared/rollup.js:18117:27)\n    at Parser.pp$8.parseImport (/Users/../node_modules/rollup/dist/shared/rollup.js:18078:28)\n    at Parser.pp$8.parseStatement (/Users/../rollup/dist/shared/rollup.js:17210:49)\n    at Parser.pp$8.parseTopLevel (/Users/../node_modules/rollup/dist/shared/rollup.js:17091:21)\n    at Parser.parse (/Users/../node_modules/rollup/dist/shared/rollup.js:16863:15)\n    at Function.parse (/Users/../node_modules/rollup/dist/shared/rollup.js:16913:35)\n    at Graph.contextParse (/Users/m../node_modules/rollup/dist/shared/rollup.js:23017:38)\n …
Run Code Online (Sandbox Code Playgroud)

build reactjs unexpected-token vite

11
推荐指数
1
解决办法
2万
查看次数

reCAPTCHA JSON 中位置 0 的意外令牌

我们使用 reCAPTCHA ver 2 作为复选框“我不是机器人”。从 2020-11-05 19:23:00Z 开始,我们在页面加载期间出现异常:

recaptcha__ru.js:211 Uncaught (in promise) SyntaxError: Unexpected token   in JSON at position 0
    at JSON.parse (<anonymous>)
    at recaptcha__ru.js:211
    at recaptcha__ru.js:209
    at Array.<anonymous> (recaptcha__ru.js:132)
    at Array.<anonymous> (recaptcha__ru.js:208)
    at GM.$ (recaptcha__ru.js:211)
    at Array.<anonymous> (recaptcha__ru.js:253)
    at QS.next (recaptcha__ru.js:416)
    at y (recaptcha__ru.js:355)
Run Code Online (Sandbox Code Playgroud)

异常发生在https://www.google.com/recaptcha/api2/anchor?ar=1&k=6LcOyt8ZAAAAAD9WJMwwwvgvSGp8Bi0zWYS-FMX5&co=aHR0cDovL2JsYWNrYmlyZDo0ODA4MA..&hl=ruz6rYmlyZDo0ODA4MA..&hl=ruz6rYmlyZDo0ODA4MA..&hl=ruz6rymlyZDo0ODA&L&70dcVh=ruz6r70dcv=ruz6rvc7uvc1&hlAZ6r70dcv=ruz6rvc7uvc1&h=ruz6r0dcv=6lOyt8ZAAAAAD9WJMwwwvgvSGp8Bi0z

在此处输入图片说明

我们的页面没有改变。reCAPTCHA 在一瞬间意外中断。在其他页面上,reCAPTCHA 仍在工作(工作页面嵌入 iframe 可能很重要)。

任何提示?什么地方出了错?

更新

正如@user2384519 建议的那样,我们尝试在我们的 JSP 页面中隔离 iframe 内的 reCAPTCHA :

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/a4j" …
Run Code Online (Sandbox Code Playgroud)

json recaptcha unexpected-token

9
推荐指数
1
解决办法
2196
查看次数

解构分配导致错误:"意外令牌="

假设我在es6中调用了这个语法:

let a, b;

{a, b} = { a: 100, b: 300 };
Run Code Online (Sandbox Code Playgroud)

代码将无错误地运行;

但是让我们改写是这样的:

function fn() {
    return { a: 100, b: 200 }
}

let a, b;

{ a, b } = fn();
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,它会显示意外的令牌"="; 我有点困惑,有什么区别?

javascript destructuring unexpected-token

7
推荐指数
1
解决办法
794
查看次数

如何修复第三方依赖项中的 Vite 构建/语法错误“Unexpected token”?

我正在尝试使用 Vite 创建 React 应用程序的生产版本。当我运行 npm run dev 命令时,应用程序将启动并且似乎可以正常工作,但在构建过程中,我总是会因某些第三方依赖项而收到此类解析器错误,表明它包含意外的令牌。

我使用的是节点 19.1.0。

我的配置文件中是否缺少某些内容或者可能是什么?

[commonjs--resolver] Unexpected token (705:2) in C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js
file: C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js:705:2
703:   toFiniteNumber,
704:   findKey,
705:   global: _global,
       ^
706:   isContextDefined,
707:   ALPHABET,
error during build:
SyntaxError: Unexpected token (705:2) in C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/axios/lib/utils.js
    at pp$4.raise (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20972:13)
    at pp$9.unexpected (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:18273:8)
    at pp$5.parseIdent (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20903:10)
    at pp$5.parsePropertyName (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20707:109)
    at pp$5.parseProperty (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20634:8)
    at pp$5.parseObj (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20597:21)
    at pp$5.parseExprAtom (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20332:17)
    at pp$5.parseExprSubscripts (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20148:19)
    at pp$5.parseMaybeUnary (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20114:17)
    at pp$5.parseExprOps (file:///C:/Users/watson.matos/Documents/Bayer/acc-ctv-front/node_modules/rollup/dist/es/shared/node-entry.js:20041:19)
Run Code Online (Sandbox Code Playgroud)

该项目是使用 React 和 TypeScript 初始化的。我必须为几个需要节点依赖项的库配置 polyfill。看起来vite.config.ts像这样:

import …
Run Code Online (Sandbox Code Playgroud)

reactjs axios unexpected-token vite

7
推荐指数
1
解决办法
8050
查看次数

未捕获到的SyntaxError:inline.bundle.js:1中出现意外的令牌&lt;-Angular v4

部署到IIS后,我发现我的路由均不起作用,因此我进行了研究,然后发现了这个问题,其中说您必须向进行重写web.config,而我已经做了,路由现在可以正常工作。

这是我的一些在开发模式下有效但在生产中有效的路线:

const appRoutes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'manage', component: ManageComponent },
  { path: 'manage/products', component: ProductComponent },
  { path: 'manage/products/:action/:id', component: ProductComponent },
  { path: 'manage/companies', component: CompanyComponent },
];  
Run Code Online (Sandbox Code Playgroud)

我所做的web.config

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*"/>
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          <add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
        </conditions>
        <action type="Rewrite" url="/"/>
      </rule>
    </rules>
  </rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

那么实际的问题是什么呢?当我刷新/重定向页面时会出现问题。经过一个小时的研究,发现我编写的规则web.config总是返回index.html …

javascript deployment iis unexpected-token angular

5
推荐指数
1
解决办法
2178
查看次数

未转译节点模块的玩笑错误

当尝试运行测试时,Jest 会抛出遇到的意外令牌错误。我正在使用 ky http,这显然会导致问题并且不会被转译。

\n\n
 Test suite failed to run\n\n    Jest encountered an unexpected token\n\n    This usually means that you are trying to import a file which Jest cannot parse, e.g. it\'s not plain JavaScript.\n\n    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".\n\n    Here\'s what you can do:\n     \xe2\x80\xa2 To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.\n     \xe2\x80\xa2 If you need …
Run Code Online (Sandbox Code Playgroud)

reactjs jestjs babeljs create-react-app unexpected-token

5
推荐指数
1
解决办法
2378
查看次数

如何使用Echo和Angular修复刷新错误

我正在设置一个Web服务器,Go(使用Echo)作为后端,Angular 6作为前端.我做的是使用Angular-cli'ng new my-app'创建一个简单的应用程序,添加一个helloworld组件和一个'/ helloworld'路径,然后使用'ng build --prod'将其构建到生产中,输出为'dist '文件夹.文件夹结构:

dist
??? assets
?   ??? icons
?   ??? logo.png
??? favicon.ico
??? index.html
??? main.js
??? polyfills.js
??? runtime.js
??? styles.css
Run Code Online (Sandbox Code Playgroud)

然后,我使用以下代码main.go为'dist'文件夹中的静态文件提供服务

func main() {
    e := echo.New()
    e.Static("/", "dist")
    e.File("/", "dist/index.html")
    e.Start(":3000")
}
Run Code Online (Sandbox Code Playgroud)

现在,当我使用浏览器并转到'localhost:3000 /'时,页面将正确提供,我可以使用href导航,感谢Angular路由,例如:'localhost:3000/home'页面将正确显示但如果我尝试刷新它,那么Echo将返回一个页面内容,显示:

{"未找到信息"}

我知道我可以手动设置路线,如下所示:

e.File("/home","dist/index.html")
Run Code Online (Sandbox Code Playgroud)

但是,如果我有更多的路线,那么完成所有这些操作是相当麻烦的.

我需要的是,没有为Echo定义的任何路由都将映射到'index.html'.我确实尝试过:

e.File("/*", "dist/index.html")
Run Code Online (Sandbox Code Playgroud)

e.GET("/*", func(c echo.Context) 
    return c.File("dist/index.html")
})
Run Code Online (Sandbox Code Playgroud)

但后来我得到一个有错误的空白页面

"Uncaught SyntaxError: Unexpected token <  " 
Run Code Online (Sandbox Code Playgroud)

所有3个文件main.js,polyfill.js和runtime.js

我是Echo的新手,所以我不知道该怎么做.

go unexpected-token angular go-echo

5
推荐指数
1
解决办法
150
查看次数

反应意外令牌&lt;-babel loader

嗨,我对babel-loader有问题,请写信给我

./src/js/pages/Admin/views/Pages/Register/Register.js中的错误模块构建失败(来自./node_modules/babel-loader/lib/index.js):语法错误:C:\ Projekty \ eshop_frontend_template \ src \ js \ pages \ Admin \ views \ Pages \ Register \ Register.js:意外令牌(7:6)

>  5 |   render() {
   6 |     return (
>  7 |       <div className="app flex-row align-items-center">
     |       ^
   8 |         <Container>
   9 |           <Row className="justify-content-center">
  10 |             <Col md="6">
at Parser.raise (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:3939:15)
at Parser.unexpected (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5248:16)
at Parser.parseExprAtom (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:6328:20)
at Parser.parseExprSubscripts (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5924:21)
at Parser.parseMaybeUnary (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5903:21)
at Parser.parseExprOps (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5812:21)
at Parser.parseMaybeConditional (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5784:21)
at Parser.parseMaybeAssign (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:5731:21)
at Parser.parseParenAndDistinguishExpression (C:\Projekty\eshop_frontend_template\node_modules\@babel\parser\lib\index.js:6474:28)
at …
Run Code Online (Sandbox Code Playgroud)

babel reactjs unexpected-token babel-loader

4
推荐指数
1
解决办法
3777
查看次数

第5行的Uncaught SyntaxError:意外的令牌

var array = [1, 2, 3, 4, 5, 6];

//print the reverse of an array

function printReverse(array){
    for(i = array.length - 1, i >= 0, i--){
        console.log(array[i])
    }
}
printReverse(array);
Run Code Online (Sandbox Code Playgroud)

上面的代码应该采用一个数组并以相反的顺序将其打印到控制台.它抛出了一个错误,我无法弄清楚为什么.

javascript unexpected-token

2
推荐指数
1
解决办法
392
查看次数