简体   繁体   English

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 } catch {

I run npm init npm i -D jest like in this tutorial我在本教程中运行npm init npm i -D jest

I am getting this error after running commend nmp test运行nmp test后出现此错误

This is not an error from creatures.js or creatures.test.js because without this file error happening.这不是来自生物.js 或生物.test.js 的错误,因为没有发生此文件错误。 How can I fix this ?我怎样才能解决这个问题 ? I tried already reinstating mode_modules.我已经尝试恢复 mode_modules。 I don't know it have a matter but I'm using node 8.17.0 because I'm working with Firebase cloud functions我不知道这有什么问题,但我正在使用节点 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包.json

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

file structure:文件结构:

![在此处输入图片说明

Upgrade node.js In old version of node they were not handled the catch block of jest file.升级 node.js 在旧版本的 node 中,它们没有处理 jest 文件的 catch 块。

It will work from node -v9.11.2 to so on.它将从 node -v9.11.2 开始工作。

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

相关问题 Jest:如何模拟 node_modules 中的库? - Jest: How to mock a library in node_modules? 从 node_modules index.js 导入 class 定义 - import class definitions from node_modules index.js 使用Jest测试时,node_modules / react-native / Libraries / Modal / Modal.js中的错误 - Error in node_modules/react-native/Libraries/Modal/Modal.js while testing with Jest 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js)Vue Js - Module build failed (from ./node_modules/babel-loader/lib/index.js) Vue Js 未捕获的错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js) - Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js) 错误 in./src/index.js 模块构建失败(来自./node_modules/babel-loader/lib/index.js): - ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js): 模块构建失败(来自 ./node_modules/babel-loader/lib/index.js) - Module build failed (from ./node_modules/babel-loader/lib/index.js) 错误:模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误: - Error: Module build failed (from ./node_modules/babel-loader/lib/index.js): SyntaxError: 模块构建失败(来自./node_modules/babel-loader/lib/index.js): - Module build failed (from ./node_modules/babel-loader/lib/index.js): 用 Jest 模拟返回函数的 node_modules? - Mocking node_modules which return a function with Jest?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM