【问题标题】:Jest js node_modules\jest\node_modules\jest-cli\build\cli\index.js:227 } catch {Jest js node_modules\jest\node_modules\jest-cli\build\cli\index.js:227 } 捕捉 {
【发布时间】:2021-02-15 23:44:58
【问题描述】:

我运行npm init npm i -D jest 就像在这个tutorial 中一样

运行推荐nmp test后出现此错误

这不是生物.js 或生物.test.js 的错误,因为没有发生此文件错误。我怎样才能解决这个问题 ?我已经尝试恢复 mode_modules。我不知道这有什么问题,但我使用的是节点 8.17.0,因为我正在使用 Firebase 云功能

PS C:\Users\Pawel\Desktop\HerosIIIJS> npm test

> heros_iii_js@1.0.0 test C:\Users\Pawel\Desktop\HerosIIIJS
> jest

C:\Users\Pawel\Desktop\HerosIIIJS\node_modules\jest\node_modules\jest-cli\build\cli\index.js:227
    } catch {
            ^

SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Pawel\Desktop\HerosIIIJS\node_modules\jest\node_modules\jest-cli\bin\jest.js:16:3)
npm ERR! Test failed.  See above for more details.
const getProjectListFromCLIArgs = (argv, project) => {
  const projects = argv.projects ? argv.projects : [];

  if (project) {
    projects.push(project);
  }

  if (!projects.length && process.platform === 'win32') {
    try {
      projects.push((0, _jestUtil().tryRealpath)(process.cwd()));
    } catch { // <= error
      // do nothing, just catch error
      // process.binding('fs').realpath can throw, e.g. on mapped drives
    }
  }

  if (!projects.length) {
    projects.push(process.cwd());
  }

  return projects;
};

package.json

{
  "name": "heros_iii_js",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "jest": "^26.6.2"
  }
}

文件结构:

【问题讨论】:

  • 节点 8 不支持可选的 catch 绑定语法,Jest 26 不再支持。
  • 这能回答你的问题吗? How to fix unexpected token in ESLint?
  • 我是否需要安装最新的节点(我不想这样做,因为 Firebase 云功能在 spark 计划中的节点 8 上工作)或者我可以选择不同的 jest 版本,我该怎么做这个?
  • 我不使用 ESLint
  • 不,您不使用 ESLint,但那里的答案解释了错误是什么以及原因,并且您有相同的选择:升级节点;或将库降级到支持 Node 8 的版本。它还显示了为第二个选项运行的命令,您只需替换名称和版本(放弃支持的版本 - 1)。

标签: javascript npm jestjs


【解决方案1】:

升级 node.js 在旧版本的节点中,他们没有处理 jest 文件的 catch 块。

它将从节点 -v9.11.2 到等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-25
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2020-12-09
    • 2020-04-09
    • 2018-10-27
    相关资源
    最近更新 更多